Toolbar doesn't set elevation on create or in XML - android

I'm currently creating an Android app for school but still want to give my best. I'm pretty new to Android development and coding in general.
The app is supposed to be a stock market game.
(Btw, I'm German, so there might be some German variables)
The app should have a similar style to Google's recent one with the Pixel 2 and Android Pie. Thus, the toolbar should have no drop shadow when created but it should appear when scrolling, like in the Pixel 2's settings app (e.g. the battery tab).
The drop shadow appears when scrolling and disappears when arriving at the top, but the toolbar starts with a drop shadow although I have set the android:elevation to 0 in the XML and also toolbar.setElevation(0) in the onCreate method.
Why does this happen? This method works in the OnScrollChangedListener!
The Java code:
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ArrayList<JSONObject> jObjList = new ArrayList<>();
private FloatingActionButton fab;
private TextView moneyTxt;
private TextView sharesTxt;
private TextView sumTxt;
private Toolbar toolbar;
private AppBarLayout toolbarLayout;
private RecyclerView recyclerShares;
private SharesAdapter sAdapter;
private NestedScrollView scrollMain;
private SwipeRefreshLayout refreshMain;
private float money;
private float sharesWorth;
private boolean isRefreshing;
private JSONObject jObj = new JSONObject();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.abMain);
toolbar.setTitleTextColor(getResources().getColor(R.color.colorPrimary));
setSupportActionBar(toolbar);
fab = findViewById(R.id.fabMain);
moneyTxt = findViewById(R.id.moneyTxt);
sharesTxt = findViewById(R.id.sharesTxt);
sumTxt = findViewById(R.id.sumTxt);
toolbarLayout = findViewById(R.id.abMainLayout);
recyclerShares = findViewById(R.id.recyclerShares);
scrollMain = findViewById(R.id.scrollMain);
scrollMain.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
refreshMain = findViewById(R.id.refreshMain);
isRefreshing = false;
try {
jObj.put("name", "BMW");
jObj.put("worth", 143.23);
jObj.put("count", 5);
jObj.put("change", -1.5);
jObjList.add(jObj);
} catch (JSONException e) {
}
sAdapter = new SharesAdapter(jObjList);
RecyclerView.LayoutManager cLayoutManager = new CustomGridLayoutManager(getApplicationContext()) {
#Override
public boolean canScrollVertically() {
return false;
}
};
recyclerShares.setLayoutManager(cLayoutManager);
recyclerShares.setItemAnimator(new DefaultItemAnimator());
recyclerShares.setAdapter(sAdapter);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SharesActivity.class);
startActivity(intent);
}
});
toolbarLayout.setElevation(0); //TODO: Stackoverflow nach Lösung fragen
scrollMain.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
#Override
public void onScrollChanged() {
int scroll = scrollMain.getScrollY();
if (scroll == 0) {
toolbarLayout.setElevation(0);
} else {
toolbarLayout.setElevation(8);
}
}
});
refreshMain.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
refresh(MainActivity.this);
}
});
refresh(MainActivity.this);
}
private void refresh(Context context) {
isRefreshing = true;
SharedPreferences sharedPref = context.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
SharedPreferences.Editor sharedPrefEdit = sharedPref.edit();
if (sharedPref.getBoolean("isFirstRun", true)) {
sharedPrefEdit.putBoolean("isFirstRun", false);
sharedPrefEdit.putFloat(getString(R.string.moneyShared), 5000);
sharedPrefEdit.apply();
}
float shareWorth = 0;
for (int i = 0; i < jObjList.size(); i++) {
try {
shareWorth += jObjList.get(i).getDouble("worth") * jObjList.get(i).getDouble("count");
} catch (JSONException e) {
}
}
sharedPrefEdit.putFloat(getString(R.string.sharesWorthShared), shareWorth);
sharedPrefEdit.commit();
money = sharedPref.getFloat(getString(R.string.moneyShared), 0);
sharesWorth = sharedPref.getFloat(getString(R.string.sharesWorthShared), 0);
moneyTxt.setText(String.format("%.2f€", money));
sharesTxt.setText(String.format("%.2f€", sharesWorth));
sumTxt.setText(String.format("%.2f€", money + sharesWorth));
if(isRefreshing) {
isRefreshing = false;
refreshMain.setRefreshing(isRefreshing);
}
Toast.makeText(MainActivity.this, "Alles neugeladen", Toast.LENGTH_SHORT).show();
}
public void onShareClick(View v) {
Intent i = new Intent(MainActivity.this, CompanyActivity.class);
try {
i.putExtra("name", jObj.getString("name"));
i.putExtra("worth", jObj.getDouble("worth"));
} catch (JSONException e) {
i.putExtra("name", "Fehler");
i.putExtra("worth", 0);
}
startActivity(i);
}
}
The XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackground"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/abMainLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/abMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBackgroundAccent"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#color/colorBackground"
android:src="#drawable/ic_note_add"
app:borderWidth="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refreshMain"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/abMainLayout">
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
app:layout_constraintTop_toBottomOf="#+id/abMainLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<GridLayout
android:id="#+id/gridMoney"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackgroundAccent"
android:orientation="horizontal"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/abMain">
<TextView
android:id="#+id/sumTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="5"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:layout_marginTop="8dp"
android:layout_row="1"
android:textColor="#color/colorDarkText"
android:textSize="50sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/moneyImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="right|center_vertical"
android:layout_row="2"
android:background="#android:color/transparent"
android:scaleX="0.5"
android:scaleY="0.5"
app:srcCompat="#drawable/ic_money" />
<TextView
android:id="#+id/moneyTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="left|center_vertical"
android:layout_row="2"
android:background="#android:color/transparent"
android:textColor="#color/colorLightText"
android:textSize="15sp" />
<ImageView
android:id="#+id/sharesImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_columnWeight="1"
android:layout_gravity="right|center_vertical"
android:layout_row="2"
android:background="#android:color/transparent"
android:scaleX="0.5"
android:scaleY="0.5"
app:srcCompat="#drawable/outline_assessment_black_36" />
<TextView
android:id="#+id/sharesTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_columnWeight="1"
android:layout_gravity="left|center_vertical"
android:layout_row="2"
android:background="#android:color/transparent"
android:textColor="#color/colorLightText"
android:textSize="15sp" />
</GridLayout>
<View
android:id="#+id/dividerMoney"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorDivider"
app:layout_constraintTop_toBottomOf="#id/gridMoney" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/recycler_horizontal_margin"
android:layout_marginStart="#dimen/recycler_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:text="Aktien"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="#+id/dividerMoney"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/gridMoney" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerShares"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/recycler_title_bottom_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>

So #NileshRathod answered it:
It's app:elevation, not android:elevation.
But I still don't get why the method in onCreate() doesn't work.

Of course, setElevation(0); won't work.
But I still don't get why the method in onCreate() doesn't work.
AppbarLayout uses StateListAnimator from v24.0.0 and that is why setElevation will has no effect on it: https://stackoverflow.com/a/37992366/4409113
So:
StateListAnimator stateListAnimator = new StateListAnimator();
stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0));
appBarLayout.setStateListAnimator(stateListAnimator);
Or:
toolbarLayout = findViewById(R.id.abMainLayout);
toolbarLayout.StateListAnimator = null;
In your case.

Related

Item List Layout showing up in Android Studio, but not in Emulator

I am working on an Android App with a Recyclerview that contains a Listview. The problem is, that the Listview items are showing up in Android Studio, that there are no errors in the XML but still, the Listview items are not showing up on the Emulator or on a Real device. I checked the Layout for all kinds of problems - Size, Width, Layout Constraints -, but I couldn´t find any. As I am stuck here, I would kindly appreciate any help or hints from the community, thanks in advance.
The Activity:
package com.example.xxx;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import okhttp3.Credentials;
import static com.example.xxx.SimpleItemRecyclerViewAdapter.TAGG;
import static com.example.xxx.SimpleItemRecyclerViewAdapter.palNo;
/**
* An activity representing a single Main detail screen. This
* activity is only used on narrow width devices. On tablet-size devices,
* item details are presented side-by-side with a list of items
* in a {#link MainListActivity}.
*/
public final class ProductDetailActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener,
PopupMenu.OnMenuItemClickListener {
public Context context;
private RecyclerView recyclerView;
private StockBookingsRecyclerviewAdapter recyclerviewAdapter;
private RecyclerTouchListener touchListener;
public static final String TAG = "Barcode ist:" ;
public String bookingType = null;
public String itemNo = null;
public String ean = null;
public String quantity = null;
public String packageCode = null;
public String target = null;
public String source = null;
public Date date;
public String scannedCode = null;
public static final String Profile_Prefs = "Pro_File";
public static SharedPreferences profile;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product_detail);
TextView titleBooking = findViewById(R.id.title_booking);
TextView typeBooking = findViewById(R.id.type_booking);
TextView nameBooking = findViewById(R.id.name_booking);
TextView dateBooking = findViewById(R.id.date_booking);
Toolbar toolbar = findViewById(R.id.toolbar);
LinearLayout linearLayout = findViewById(R.id.rowFGP);
String selectedItem =null;
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.mockdata, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
String basic = Credentials.basic("xxx", "xxx");
// Apply the adapter to the spinner
recyclerView = findViewById(R.id.recyclerview2);
recyclerviewAdapter = new StockBookingsRecyclerviewAdapter(this);
Intent newIntent = getIntent();
String receivedPalNo = newIntent.getStringExtra("palNo");
String receivedNo = newIntent.getStringExtra("no");
String receivedType = newIntent.getStringExtra("type");
String receivedRack = newIntent.getStringExtra("rack");
String receivedCountItems = newIntent.getStringExtra("count_items");
RestClient.getStockBookings(getApplicationContext(),recyclerviewAdapter,basic);
Log.d(TAGG,"Intent 1" + receivedPalNo);
Log.d(TAGG, "Intent 2" + receivedNo);
Log.d(TAGG, "Intent 3" + receivedType);
Log.d(TAGG,"Intent 4" + receivedRack);
Log.d(TAGG, "Intent 5" + receivedCountItems);
//use a GradientDrawable with only one color set, to make it a solid color
GradientDrawable border = new GradientDrawable();
border.setColor(0x00000000); //white background
border.setStroke(1, 0xFF000000); //black border with full opacity
final ArrayList<StockBookings> stockBookingList = new ArrayList<>();
recyclerviewAdapter. setBookingList((ArrayList<StockBookings>) stockBookingList);
recyclerView.setAdapter(recyclerviewAdapter);
touchListener = new RecyclerTouchListener(this,recyclerView);
StockBookingsRecyclerviewAdapter finalRecyclerviewAdapter = recyclerviewAdapter;
touchListener
.setClickable(new RecyclerTouchListener.OnRowClickListener() {
#Override
public void onRowClicked(int position) {
}
#Override
public void onIndependentViewClicked(int independentViewID, int position) {
}
})
.setSwipeOptionViews(R.id.delete_task)
.setSwipeable(R.id.rowFGP, R.id.rowBGP, new RecyclerTouchListener.OnSwipeOptionsClickListener() {
#Override
public void onSwipeOptionClicked(int viewID, int position) {
stockBookingList.remove(position);
finalRecyclerviewAdapter.setStockBookingList(stockBookingList);
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onBackPressed() {
Intent setIntent = new Intent(getApplicationContext(),MainListActivity.class);
startActivity(setIntent);
}
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(this, "Selected Item: " +item.getTitle(), Toast.LENGTH_SHORT).show();
switch (item.getItemId()) {
case R.id.search_item:
// do your code
return true;
case R.id.upload_item:
// do your code
return true;
case R.id.copy_item:
// do your code
return true;
/* case R.id.print_item:
// do your code
return true;*/
case R.id.share_item:
// do your code
return true;
/*case R.id.bookmark_item:
// do your code
return true;*/
default:
return false;
}
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
navigateUpTo(new Intent(this, MainListActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onResume() {
super.onResume();
recyclerView.addOnItemTouchListener(touchListener);
}
#Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
}
The Activity XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="#dimen/_80sdp"
android:layout_marginBottom="12dp"
android:layout_weight="0.15"
android:background="#drawable/border_set"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#id/recyclerview2">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:text="#string/product_bookings"
android:textColor="#color/black"
android:textSize="#dimen/_20sdp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/txt1"
app:layout_constraintEnd_toEndOf="#id/txt1" />
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="#string/nicht_uebertragen"
android:textColor="#color/black"
android:textSize="#dimen/_10sdp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/txt1"
app:layout_constraintEnd_toEndOf="#id/txt1" />
</LinearLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview2"
android:layout_width="match_parent"
android:layout_height="#dimen/_280sdp"
android:layout_weight="0.7"
tools:itemCount="7"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintTop_toBottomOf="#+id/linearLayout"
tools:listitem="#layout/product_item" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="#dimen/_110sdp"
android:layout_weight="0.15"
android:gravity="bottom"
android:padding="5dp"
app:layout_constraintTop_toBottomOf="#id/recyclerview2"
tools:layout_editor_absoluteX="0dp">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:contentDescription="#string/fab_content_desc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_add_circle_outline" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
The Product Item XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_border"
android:orientation="vertical">
<LinearLayout
android:id="#+id/rowBGP"
android:background="#color/colorPrimaryDark"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:gravity="right"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/delete_task"
android:layout_width="50dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/img_delete"
android:layout_width="50dp"
android:layout_marginTop="#dimen/_1sdp"
android:layout_height="59dp"
android:background="#color/light_red"
android:text="#string/edit_article"
android:textSize="12dp"
android:textStyle="bold|italic"
app:tint="#android:color/white" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/rowFGP"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#android:color/white"
android:clickable="true"
android:elevation="4dp"
android:focusable="true"
android:orientation="horizontal"
android:layout_margin="1dp"
android:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?attr/selectableItemBackground">
<TextView
android:id="#+id/title_booking"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/_2sdp"
android:layout_marginBottom="32dp"
android:lines="1"
android:text="#string/product_bookings"
android:textFontWeight="900"
android:textSize="#dimen/_15sdp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.888" />
<TextView
android:id="#+id/type_booking"
android:text="#string/booking_type"
style="#style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="#dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.265"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.615" />
<TextView
android:id="#+id/name_booking"
android:text="#string/name_booking"
style="#style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:textSize="#dimen/_15sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.265"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.615" />
<TextView
android:id="#+id/date_booking"
android:text="#string/date_booking"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:lines="1"
android:textFontWeight="900"
android:textSize="#dimen/_15sdp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.888"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</RelativeLayout>
When you are setting the Adapter, stockBookingList is empty.
This means that when RecyclerView decides to render items on the list, it finds the itemCount to be 0.
This instructs the RecylcerView to not render anything on the list, since it won't call onCreateViewHolder or onBindViewHolder – two methods responsible for inflating your list item and setting necessary data.
If you have a static list of items, you need to provide them to the adapter.
If the list is coming from your RestClient, you need update the adapter as and when you receive data from your API.

Android Initial Login Screen then use fragments to swipe between screens once login is successful

I am trying to create an Android app, then has an initial login screen that detects if a user is Admin or User. Once logged in, the user (depending on their role) will see different tabs to swipe between. I have a basic app that starts with a login activity and the login to decipher the users roles (using static values for now). First part is ok. Now when I try to use Fragments after the login screen, I'm getting stuck.
I have a LoginActivity that has an onClikcListener on a button after user enters credentials. Depending on whether the user is Amin or General Users, it will just to a new activity either activity_vote_admin or activity_vote_user. At this point I am stuck. Any ideas if what I am trying to do is valid. Or is there a better way to do this. At the moment I am getting this error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.confidencevotefragmentrebuild/com.example.confidencevotefragmentrebuild.activity_vote_admin}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference.
LoginActivity (this is my main activity)
...
package com.example.confidencevotefragmentrebuild;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity {
private static EditText username;
private static EditText password;
public static TextView attempts;
private static Button submit_button;
int attempt_counter = 5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loginButton();
}
public void loginButton() {
username = (EditText) findViewById(R.id.editText);
password = (EditText) findViewById(R.id.editText2);
attempts = (TextView) findViewById(R.id.textView_Attempts);
//Reference button view
final Button submit_button = findViewById(R.id.submit_button);
// perform click event on button
submit_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (username.getText().toString().equals("admin") &&
password.getText().toString().equals("pass")) {
Toast.makeText(LoginActivity.this, "Welcome " + username.getText(),
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this, activity_vote_admin.class);
startActivity(intent);
} else if (username.getText().toString().equals("user") &&
password.getText().toString().equals("pass")) {
Toast.makeText(LoginActivity.this, "Welcome " + username.getText(),
Toast.LENGTH_SHORT).show();
Intent intentUser = new Intent(LoginActivity.this, activity_vote_user.class);
startActivity(intentUser);
} else {
Toast.makeText(LoginActivity.this, "User or Password incorrect",
Toast.LENGTH_SHORT).show();
attempt_counter--;
attempts.setText(Integer.toString(attempt_counter));
if (attempt_counter == 0) {
Toast.makeText(LoginActivity.this, "Too many failed attempts, please close app and try again",
Toast.LENGTH_SHORT).show();
submit_button.setEnabled(false);
}
}
}
}
);
}
}
...
Activity_vote_admin
...
package com.example.confidencevotefragmentrebuild;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
public class activity_vote_admin extends AppCompatActivity {
/**
* Field for selecting the number of confidence votes
*/
RatingBar mResults;
private RatingBar rBar;
Button mBtn;
/**
* Spinner field to enter the project name
*/
private Spinner mProjectSpinner;
/**
* Projects. The possible values are:
* stored locally - Needs to get values from a database. TODO
*/
int mProject = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vote_main_admin);
// Find the view pager that will allow the user to swipe between fragments
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
// Create an adapter that knows which fragment should be shown on each page
AdminFragmentPagerAdapter adapter = new AdminFragmentPagerAdapter(getSupportFragmentManager());
// Set the adapter onto the view pager
viewPager.setAdapter(adapter);
// initiate a rating bar
rBar = findViewById(R.id.rating_bar);
//float vote = rBar.getRating();
// Find all relevant views for user input
mResults = findViewById(R.id.rating_bar);
mProjectSpinner = findViewById(R.id.spinner_project);
// Run getRating method to get rating number from a rating bar
//getRating();
// Initiate button
mBtn = findViewById(R.id.voteButton);
// perform click event on button
mBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// get values and then displayed in a toast
//String totalStars = "Total Stars:: " + RatingBar.getNumStars();
float vote = rBar.getRating();
String rating = "Rating : " + vote;
Toast.makeText(getApplicationContext(), rating + "\n", Toast.LENGTH_LONG).show();
}
});
projectSpinner();
}
// Setup the dropdown spinner that allows the user to select the role.
private void projectSpinner() {
// Create adapter for spinner. The list options are from the String array it will use
// the spinner will use the default layout
ArrayAdapter projectSpinnerAdapter = ArrayAdapter.createFromResource(this,
R.array.projects, android.R.layout.simple_spinner_item);
// Specify dropdown layout style - simple list view with 1 item per line
projectSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
// Apply the adapter to the project spinner
mProjectSpinner.setAdapter(projectSpinnerAdapter);
// Set the integer mSelected to the constant values
mProjectSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selection = (String) parent.getItemAtPosition(position);
if(mProjectSpinner.getSelectedItem() == "This is Hint Text");
if (!TextUtils.isEmpty(selection)) {
if (selection.equals(getString(R.string.nextGEMS1_5))) {
mProject = 0 ;
return;
} else if (selection.equals(getString(R.string.nextGEMS1_6))) {
mProject = 1;
return;
} else if (selection.equals(getString(R.string.nextGEMS1_7))) {
mProject = 2;
return;
} else if (selection.equals(getString(R.string.nextGEMS1_8))) {
mProject = 3;
return;
} else if (selection.equals(getString(R.string.nextGEMS1_9))) {
mProject = 4;
return;
}
else mProject = 0;
}
}
// Because AdapterView is an abstract class, onNothingSelected must be defined
#Override
public void onNothingSelected(AdapterView<?> parent) {
mProject = 0; // User
}
});
}
}
...
activity_vote_main_admin.xml
...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.viewpager.widget.ViewPager
android:name="com.example.confidencevotefragmentrebuild.testFragment1"
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
...
activity_login.xml
...
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".LoginActivity"
tools:showIn="#layout/activity_login">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5fb0c9"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView
android:id="#+id/login_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:gravity="center_horizontal"
android:text="LOGIN"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="500dp"
android:background="#ffffff"
android:elevation="4dp"
android:orientation="vertical"
android:padding="20dp"
android:layout_below="#+id/login_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="80dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="450dp"
android:orientation="vertical"
android:paddingTop="30dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp">
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:drawableLeft="#drawable/usericon"
android:hint="User Name"
android:inputType="textEmailAddress"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:drawableLeft="#drawable/lock"
android:hint="Password"
android:inputType="textPassword"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:paddingTop="5dp"
android:text="Forgot Password?" />
<Button
android:id="#+id/submit_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:background="#drawable/action_buttom"
android:text="Sign in"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal"
android:paddingTop="1dp">
<TextView
android:id="#+id/attempts_text"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:paddingTop="1dp"
android:text="Number of attempts remaining: " />
<TextView
android:id="#+id/textView_Attempts"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:paddingTop="1dp"
android:text="5" />
</LinearLayout>
<TextView
android:id="#+id/lnkRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:gravity="center"
android:paddingTop="30dp"
android:text="Register here"
android:textColor="#5fb0c9"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
<ImageButton
android:id="#+id/conferencevote_logo"
android:layout_width="210dp"
android:layout_height="180dp"
android:layout_below="#+id/login_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:elevation="4dp"
android:background="#drawable/rounded_button"
android:src="#drawable/confvotenew"
/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
...
AdminFragemntyPagerAdapter
...
package com.example.confidencevotefragmentrebuild;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
public class AdminFragmentPagerAdapter extends FragmentPagerAdapter {
public AdminFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
if (position == 0) {
return new testFragment1();
} else if (position == 1) {
return new testFragment2();
} else {
return new testFragment2();
}
}
#Override
public int getCount() {
return 3;
}
}
...
aactivity_vote_user.xml
...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5fb0c9"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView
android:id="#+id/vote_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:gravity="center_horizontal"
android:text="USER VOTE"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="500dp"
android:background="#ffffff"
android:elevation="4dp"
android:orientation="vertical"
android:padding="20dp"
android:layout_below="#+id/vote_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="80dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="450dp"
android:orientation="vertical"
android:paddingTop="70dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<Spinner
android:id="#+id/spinner_project"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:hint="#string/spinner_hint"
android:maxLines="1"
android:singleLine="true"
android:backgroundTint="#color/attCobalt"
android:popupBackground="#color/myBlue"
android:dropDownSelector="#color/attBlue"
/>
</com.google.android.material.textfield.TextInputLayout
>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<RatingBar
android:id="#+id/rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stepSize="1.0"
android:layout_marginTop="40dp"
android:theme="#style/rating_bar"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="5dp"
android:text="Vote and Submit" />
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/voteButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:background="#drawable/action_buttom"
android:text="Submit"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
/>
</LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<ImageButton
android:id="#+id/conferencevote_logo"
android:layout_width="210dp"
android:layout_height="180dp"
android:layout_below="#+id/login_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:elevation="4dp"
android:background="#drawable/rounded_button"
android:src="#drawable/confvotenew"
/>
</RelativeLayout>
...
My fragments are as follows.
...
package com.example.confidencevotefragmentrebuild;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
public class testFragment1 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_vote_user, container, false);
}
}
...
There are two reason for this issue :
You didn't declare any button on "activity_vote_main_admin.xml", thats why your view not binding with activity and giving null pointer exception.
May be you declare the button on fragment xml and trying to bind it with activity.

I'm having trouble with phone number authentication. Verify_otp generates a unique code for any verified number

I'm having trouble with phone number authentication. Verify_otp generates a unique code for any verified number. But the biggest problem is that it only generates the code if the numbers start with 6599 ..... a number 6598 .... it no longer generates the code.
I can not find an outlet for him to accept any phone number.
this is a part of the RegistrationModel.java file
public static class OTP_Details{
/**
* status : 2
* message : Otp Sent to phone for Verification
* otp : 2017
* auto_otp : 1
*/
private int status;
private String message;
private String otp;
private int auto_otp;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getOtp() {
return otp;
}
public void setOtp(String otp) {
this.otp = otp;
}
public int getAuto_otp() {
return auto_otp;
}
public void setAuto_otp(int auto_otp) {
this.auto_otp = auto_otp;
}
}
}
This is Vetify_otp
package com.motofacil.passageiro;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.motofacil.passageiro.accounts.RegistrationModel;
import com.motofacil.passageiro.accounts.ResultCheckMessage;
import com.motofacil.passageiro.accounts.ResultChecker;
import com.motofacil.passageiro.manager.ApiManager;
import com.motofacil.passageiro.manager.SessionManager;
import com.motofacil.passageiro.samwork.Config;
import com.motofacil.passageiro.urls.Apis;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hbb20.CountryCodePicker;
import java.util.HashMap;
public class Verify_OTP extends AppCompatActivity implements ApiManager.APIFETCHER {
ApiManager apiManager ;
GsonBuilder gsonBuilder;
RegistrationModel.OTP_Details otp_details;
private TextView otpError_txt;
private EditText otp_input, edt_enter_phone;
private LinearLayout submit_otp_layout;
SessionManager sessionManager ;
Gson gson;
String code, input_phone_number, otp;
CountryCodePicker codePicker;
private static final int KEY_REGISTER = 110;
Button generate_otp;
LinearLayout submit_otp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gsonBuilder = new GsonBuilder();
gson = gsonBuilder.create();
apiManager = new ApiManager(this , this , this );
sessionManager = new SessionManager(Verify_OTP.this);
otp_details = new RegistrationModel.OTP_Details();
setContentView(R.layout.activity_verify__otp);
gsonBuilder = new GsonBuilder();
gson = gsonBuilder.create();
submit_otp = (LinearLayout) findViewById(R.id.otp_submit);
generate_otp = (Button) findViewById(R.id.generate_otp);
edt_enter_phone = (EditText)findViewById(R.id.edt_enter_phone);
otp_input = (EditText)findViewById(R.id.otp_edt);
otpError_txt = (TextView)findViewById(R.id.otp_verifier_txt);
submit_otp_layout = (LinearLayout)findViewById(R.id.otp_submit);
codePicker = (CountryCodePicker)findViewById(R.id.otp_ccp);
submit_otp.setEnabled(false);
generate_otp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
input_phone_number = edt_enter_phone.getText().toString().trim();
Log.e("input_phone_number====", input_phone_number);
code = codePicker.getSelectedCountryCodeWithPlus();
Log.e("COUNTRY_CODE_PICKER===", code);
if (input_phone_number.equals("")){
Toast.makeText(Verify_OTP.this, R.string.required_field_missing, Toast.LENGTH_SHORT).show();
}else {
getOTP(code+input_phone_number);
}
}
});
submit_otp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (otp_input.getText().toString().equals("")) {
Toast.makeText(Verify_OTP.this, R.string.required_field_missing, Toast.LENGTH_SHORT).show();
} else if (!otp_input.getText().toString().equals(otp)) {
// Toast.makeText(Verify_OTP.this, R.string.invalid_otp, Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("phone_number", code + input_phone_number);
setResult(Activity.RESULT_OK, intent);
finish();
} else {
Intent intent = new Intent();
intent.putExtra("phone_number", code + input_phone_number);
setResult(Activity.RESULT_OK, intent);
finish();
}
}
});
}
private void getOTP(String phone) {
HashMap<String , String > bodyparameters = new HashMap<String, String>();
bodyparameters.put("phone" , phone);
bodyparameters.put("flag" ,"1");
apiManager.execution_method_post(Config.ApiKeys.KEY_VERIFY_OTP ,""+ Apis.SEND_OTP, bodyparameters, true,ApiManager.ACTION_SHOW_TOP_BAR);
}
#Override
public void onFetchComplete(Object script, String APINAME) {
if(APINAME.equals(""+Config.ApiKeys.KEY_VERIFY_OTP)){
submit_otp.setEnabled(true);
RegistrationModel.OTP_Details otp_response = gson.fromJson("" + script, RegistrationModel.OTP_Details.class);
// finilalizeActivity();
Log.e("**OTP_SCRIPT-----", String.valueOf(otp_response.getMessage() + otp_response.getOtp() + otp_response.getStatus()));
otp = otp_response.getOtp();
Log.d("otp==normal sign up==", otp);
otp_input.setText(""+otp);
otp_input.requestFocus();
if(otp_response.getAuto_otp() == 1){
otp_input.setText(""+otp);
}
}else {
try{ResultChecker rcheck = gson.fromJson("" + script, ResultChecker.class);
Log.e("**OTP_SCRIPT-----", String.valueOf(script));
if(rcheck.getResult() == 1){
Log.e("**RCHHECKK---", String.valueOf(rcheck.getResult()));
RegistrationModel.OTP_Details otp_response = gson.fromJson("" + script, RegistrationModel.OTP_Details.class);
}else {
ResultCheckMessage rr = gson.fromJson("" + script, ResultCheckMessage.class);
Toast.makeText(this, ""+rr.getMessage(), Toast.LENGTH_SHORT).show();
}
}catch (Exception e){}
}
}
#Override
public void onFetchResultZero(String s) {
}
}
This is Activity_forgotpass_verify_otp.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.motofacil.passageiro.ForgotPass_Verify_OTP">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/pure_white"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/otp_back"
android:layout_width="50dp"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="invisible">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/ic_left_sort"
android:tint="#color/icons_8_muted_grey"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<com.motofacil.passageiro.accounts.TypefaceDosisRegular
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/verifyOTP"
android:textColor="#color/icons_8_muted_grey"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="50dp"
android:layout_height="match_parent" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/icons_8_muted_grey" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/login_banner"></ImageView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bf000000"></RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/icons_8_muted_grey" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|top"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="#+id/phone_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="15dp"
android:background="#drawable/shapes_white_transparent"
android:layout_marginRight="15dp"
android:gravity="center"
android:orientation="horizontal">
<com.hbb20.CountryCodePicker
android:id="#+id/otp_ccp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:hideNameCode="true"
app:keyboardAutoPopOnSearch="false"
app:showFlag="false"
android:layout_marginLeft="5dp"
app:defaultCode="55"
app:textSize="15dp"/>
<EditText
android:id="#+id/edt_enter_phone"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:background="#android:color/transparent"
android:ems="10"
android:drawableTint="#color/icons_8_muted_grey"
android:gravity="center|left"
android:hint="Enter Phone Number"
android:inputType="phone"
android:maxLength="10"
android:minLines="1"
android:padding="5dp"
android:textColor="#color/pure_black"
android:textSize="17dp" />
</LinearLayout>
<!--
<View
android:layout_width="match_parent"
android:layout_height="0.85dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="6dp"
android:background="#color/icons_8_muted_yellow" />-->
<Button
android:id="#+id/generate_otp"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/generateOTP" />
<TextView
android:id="#+id/otp_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:text="#string/otp_text"
android:textColor="#color/pure_white"
android:textSize="17dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="70dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="30dp"
android:background="#drawable/shapes_white_transparent"
android:orientation="horizontal">
<EditText
android:id="#+id/otp_edt"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
android:drawableTint="#color/icons_8_muted_grey"
android:gravity="center|left"
android:hint="#string/enter_otp"
android:inputType="number"
android:paddingLeft="10dp"
android:textColor="#color/pure_black"
android:textSize="17dp" />
<TextView
android:id="#+id/otp_verifier_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center|right"
android:padding="10dp"
android:text="Email not valid"
android:textColor="#color/icons_8_muted_red"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/otp_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/colorPrimary"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/submitOTP"
android:textColor="#color/pure_white"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
Ready! I've submitted below the files I've listed. After typing the phone and clicking send otp, the code that comes back is always the code 2017, that is the first code I sent, but it only sends this code 2017 if the numbers start like this: 6599 .... if the number is so for example: 6598 .... it does not generate the code 2017 and can not continue the registration.

how to move main content and action bar to right in navigation drawer using fragments

i have a custom navigation drawer that opens from left to right using fragment. i want to move my content and action bar to right when navigation opens, i read some sources, they override onDrawerSlide method to do so, but since i using fragment to open and close navigation, i do not have such a method to override, I'll be grateful someone could help me (:
I tried this link to move the contents
and used this to create a custom navigation view
there is main activity :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container">
<TextView
android:id="#+id/homeContents"
android:text="this is gonna be ur main page"
android:layout_width="200dp"
android:layout_height="46dp" />
</FrameLayout>
</LinearLayout>
and this is drawer :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/rootLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/nav_profile"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:layout_width="77dp"
android:layout_height="77dp"
android:src="#drawable/ic_user"
/>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:drawableLeft="#drawable/ic_user_plus"
android:drawablePadding="5dp"
android:paddingLeft="10dp"
android:id="#+id/sign_in"
android:layout_width="91dp"
android:layout_height="40dp"
android:layout_marginStart="20dp"
android:background="#drawable/more_btn_coop_req"
android:text="SIGNUP"
android:textColor="#color/blue" />
<Button
android:drawableLeft="#drawable/ic_sign_in_alt"
android:drawablePadding="5dp"
android:paddingLeft="10dp"
android:id="#+id/sign_up"
android:layout_width="91dp"
android:layout_height="40dp"
android:layout_marginStart="25dp"
android:background="#drawable/more_btn_coop_req"
android:text="ENTER"
android:textColor="#color/blue" />
</LinearLayout>
<Spinner
android:layout_marginTop="16dp"
android:background="#drawable/spinner_background"
android:id="#+id/cities_spinner"
android:layout_gravity="center"
android:layout_width="190dp"
android:layout_height="40dp">
</Spinner>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_marginTop="250dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:drawableLeft="#drawable/ic_check"
android:drawablePadding="25dp"
android:id="#+id/bookmark_centers"
android:layout_gravity="center"
android:background="#drawable/drawer_buttons_style"
android:text="تخفیف های نشان شده"
android:layout_width="186dp"
android:layout_height="40dp" />
<Button
android:drawableLeft="#drawable/ic_store"
android:id="#+id/followed_centers"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:background="#drawable/drawer_buttons_style"
android:text="مراکز دنبال شده"
android:layout_width="186dp"
android:layout_height="40dp" />
<Button
android:id="#+id/tems"
android:drawableLeft="#drawable/ic_info"
android:background="#drawable/drawer_buttons_style"
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:text="شرایط استفاده"
android:layout_width="186dp"
android:layout_height="40dp" />
<Button
android:id="#+id/contact_us"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:drawableLeft="#drawable/ic_phone"
android:background="#drawable/drawer_buttons_style"
android:text="ارتباط با ما"
android:layout_width="186dp"
android:layout_height="40dp" />
<Button
android:id="#+id/share_us"
android:layout_gravity="center"
android:text="پیشنهاد به دوستان"
android:layout_marginTop="10dp"
android:drawableLeft="#drawable/ic_share_alt"
android:background="#drawable/drawer_buttons_style"
android:layout_width="186dp"
android:layout_height="40dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<Button
android:id="#+id/EXIT"
android:layout_width="72sp"
android:layout_height="40dp"
android:layout_marginStart="32dp"
android:background="#drawable/drawer_buttons_style"
android:drawableLeft="#drawable/ic_sign_out_alt"
android:text="خروج" />
<Button
android:id="#+id/edit"
android:layout_width="105dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:background="#drawable/drawer_buttons_style"
android:drawableLeft="#drawable/ic_cog"
android:text="ویرایش" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
there is a custom toolbar and base activity that merged both toolbar and
drawer, but i think it is not necessary.
this is menu fragment class :
package TestNavigationDrawer;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import com.example.deathstroke.uniqueoff1.R;
public class MenuFragment extends Fragment implements
View.OnTouchListener {
GestureDetector gestureDetector;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.slider_menu, container,
false);
RelativeLayout root = rootView.findViewById(R.id.rootLayout);
/*gestureDetector=new GestureDetector(getActivity(),new
OnSwipeListener(){
#Override
public boolean onSwipe(Direction direction) {
if (direction==Direction.up){
//do your stuff
((MainActivity ) getActivity()).hideFragment();
}
if (direction==Direction.down){
//do your stuff
}
return true;
}
});
root.setOnTouchListener(this);*/
return rootView;
}
#Override
public boolean onTouch(View v, MotionEvent event) {
gestureDetector.onTouchEvent(event);
return true;
}
}
and there is mainActivity class :
package com.example.deathstroke.uniqueoff1;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import TestNavigationDrawer.*;
public class MainActivity extends BaseActivity {
boolean isFragmentLoaded;
Fragment menuFragment;
TextView title;
ImageView menuButton;
RelativeLayout rootLayout;
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.e("onCreate", "onCreate: " );
super.onCreate(savedInstanceState);
initAddlayout(R.layout.activity_main);
Log.e("onCreate", "onCreate: " );
rootLayout = findViewById(R.id.rootLayout);
textView = findViewById(R.id.homeContents);
title = findViewById(R.id.title_top);
menuButton = findViewById(R.id.menu_icon);
title.setText("Menu Activity");
menuButton.setOnClickListener((View)-> {
try {
if (!isFragmentLoaded) {
loadFragment();
title.setText("Profile");
} else {
if (menuFragment != null) {
if (menuFragment.isAdded()) {
hideFragment();
}
}
}
}catch (Exception e){
Log.e("Menu", "onCreate: menu on click, e: " + e);
}
});
}
public void hideFragment(){
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_left,
R.anim.slide_right);
fragmentTransaction.remove(menuFragment);
fragmentTransaction.commit();
menuButton.setImageResource(R.drawable.ic_menu);
isFragmentLoaded = false;
title.setText("Main Activity");
}
public void loadFragment(){
FragmentManager fm = getSupportFragmentManager();
menuFragment = fm.findFragmentById(R.id.container);
menuButton.setImageResource(R.drawable.ic_up_arrow);
if(menuFragment == null){
menuFragment = new MenuFragment();
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_left,
R.anim.slide_right);
fragmentTransaction.add(R.id.container,menuFragment);
fragmentTransaction.commit();
}
isFragmentLoaded = true;
}
}
as you can see, i am using loadFragment and hideFragment to open and close drawer, so how can i move main content (there is a simple textview but consider it whole lots of stuff)
Hey you can use this I guess you want the same output
The below link

Why pass textInput content to string into ArrayList

I want pass values from a form making with TextInputLayout but Android Studio detects my content as INT.
I put the complete class of my activity as well as the view in .xml to determine the problem
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.prosegma.rso.R;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class AccionActivity extends AppCompatActivity {
ImageView imageView;
private Context activity;
private String[]header={"Campo","Respuesta"};
private String shortText="RSO PROSEGMA";
private String longText="Eliminamos Riesgos Sumamos Valor";
private AccionPdf accionPdf;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accion);
Button btnCamera1 = (Button)findViewById(R.id.BtnCamera1);
imageView = (ImageView)findViewById(R.id.reporte1);
btnCamera1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,0);
}
});
Date date = new Date();
String timeStamp = new SimpleDateFormat("dd/MM/yyyy").format(date);
accionPdf=new AccionPdf(getApplicationContext());
accionPdf.openDocument();
accionPdf.addMetaData("Reporte","Acción Insegura","www.prosegma.com");
accionPdf.addTitle("Reporte Acción Insegura","RSO Prosegma"," " +timeStamp);
accionPdf.addParagraph(shortText);
accionPdf.addParagraph(longText);
accionPdf.createTable(header,getClients());
accionPdf.closeDocument();
}
TextInputEditText Nreport = (TextInputEditText) findViewById(R.id.nReporta);
private ArrayList<String[]>getClients(){
ArrayList<String[]>rows=new ArrayList<>();
rows.add(new String[]{"Nombre de quien reporta", Nreport });
rows.add(new String[]{"Nombre del trabajador","No"});
rows.add(new String[]{"Empresa contratista","ju"});
rows.add(new String[]{"Medidas Necesarias","hu"});
return rows;
}
public void pdfAccion(View view)
{
accionPdf.verReporteAccion();
}
public void enviarA(View view) {
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, "receiver_email_address");
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "email body");
Uri uri = Uri.fromFile(new File(android.os.Environment.getExternalStorageDirectory(), "pdfFileName"));
email.putExtra(Intent.EXTRA_STREAM, uri);
email.setType("application/pdf");
email.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(email);
}
public Context getActivity() {
return activity;
}
}
I update the publication with the activity, I have tried to change the InputTextLayout by EditText but the situation is the same, it throws me an incompatibility error.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="#layout/actionbar_toolbar"/>
<ScrollView
android:id="#+id/reportes0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:id="#+id/reportes1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:weightSum="10"
>
<View
android:layout_width="match_parent"
android:layout_height="7dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
/>
<View
android:layout_width="match_parent"
android:layout_height="7dp"
/>
<ImageView
android:id="#+id/reporte1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/BtnCamera1"
android:layout_weight="1"
android:layout_height="64sp"
android:layout_width="64sp"
android:background="#drawable/camera"
android:gravity="center"
/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/nReporta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="NOMBRE DE QUIEN REPORTA"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/nTrabajador"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="NOMBRE DEL TRABAJADOR"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/eContratista"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EMPRESA CONTRATISTA"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/aMedidas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:hint="ACCIÓN, MEDIDAS CORRECTIVAS INMEDIATAS"
android:inputType="textShortMessage"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
</android.support.design.widget.TextInputLayout>
<CheckBox
android:id="#+id/checkAccidente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ACCIDENTE" />
<CheckBox
android:id="#+id/checkImpacto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IMPACTO AMBIENTAL" />
<CheckBox
android:id="#+id/checkEnfermedad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENFERMEDAR PROFESIONAL" />
<CheckBox
android:id="#+id/checkReincidente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REINCIDENTE" />
<CheckBox
android:id="#+id/checkSancion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="¿APLICA SANCIÓN?"
/>
<Button
android:id="#+id/guardarAccion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GUARDAR REPORTE"
android:theme="#style/RaisedButtonDark"
android:onClick="pdfAccion"
/>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
TextInputEditText Nreport = (TextInputEditText) findViewById(R.id.nReporta);
this line is outside OnCreate(Bundle savedInstanceState) method. Thats why it throws null. It should be like this
public class MainActivity extends AppCompatActivity {
TextInputEditText Nreport;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Button btnCamera1 = (Button)findViewById(R.id.BtnCamera1);
// imageView = (ImageView)findViewById(R.id.reporte1);
Date date = new Date();
String timeStamp = new SimpleDateFormat("dd/MM/yyyy").format(date);
Nreport = (TextInputEditText) findViewById(R.id.nReporta);
getClients();
}
private ArrayList<String[]> getClients(){
ArrayList<String[]>rows=new ArrayList<>();
rows.add(new String[]{"Nombre de quien reporta", Nreport.getText().toString() }); // get text like this
rows.add(new String[]{"Nombre del trabajador","No"});
rows.add(new String[]{"Empresa contratista","ju"});
rows.add(new String[]{"Medidas Necesarias","hu"});
return rows;
}

Categories

Resources