send sms automatically using firebase database given phone number and date - java

Firebase database screenshot
I'm a beginner at android and firebase and am developing a driving school app.
I am to successfully add customer details to a firebase database ('name', 'phone', 'fromdate' and 'todate'). I want to send an sms alert to the customer e.g. ("your licence is expiry soon.") using 'phone' and 'date' from the firebase database. The sms should be sent 7 days before the expiry date (I mean 'todate' in the firebase database). Here I've attached my firebase database screenshot. Please give me an example of how to do this.
Update customer details
public class Updatecustomer extends AppCompatActivity {
private EditText edtname, edtpho;
private Button btnsubmit;
private EditText datepickerto, datepickerfr;
private Calendar mcurrentDate, mlateDate;
int day, month, year;
private DatabaseReference childref;
private DatabaseReference listref;
private DatabaseReference noderef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_updatecustomer);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("Update your Customer Details");
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
datepickerto = (EditText)findViewById(R.id.datepickerto);
datepickerfr = (EditText)findViewById(R.id.datepickerfr);
edtname = (EditText)findViewById(R.id.edtname);
edtpho = (EditText)findViewById(R.id.edtpho);
btnsubmit = (Button)findViewById(R.id.btnsubmit);
mcurrentDate = Calendar.getInstance();
day = mcurrentDate.get(Calendar.DAY_OF_MONTH);
month = mcurrentDate.get(Calendar.MONTH);
year = mcurrentDate.get(Calendar.YEAR);
day = day+1;
datepickerto.setText(day+"-"+month+"-"+year);
datepickerto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DatePickerDialog datePickerDialog = new
DatePickerDialog(Updateproduction.this, new
DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int
monthOfYear, int dayOfMonth) {
monthOfYear =monthOfYear+1;
datepickerto.setText(dayOfMonth+"-"+monthOfYear+"-
"+year);
}
}, year, month, day);
datePickerDialog.show();
}
});
mlateDate = Calendar.getInstance();
day = mlateDate.get(Calendar.DAY_OF_MONTH);
month = mlateDate.get(Calendar.MONTH);
year = mlateDate.get(Calendar.YEAR);
month = month+1;
datepickerfr.setText(day+"-"+month+"-"+year);
datepickerfr.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DatePickerDialog datePickerDialog = new
DatePickerDialog(Updatecustomer.this, new
DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int
monthOfYear, int dayOfMonth) {
monthOfYear =monthOfYear+1;
datepickerfr.setText(dayOfMonth+"-"+monthOfYear+"-
"+year);
}
}, year, month, day);
datePickerDialog.show();
}
});
final FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference table_user = database.getReference();
childref = table_user.child("Rajadriving");
btnsubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final ProgressDialog mDiaglog = new
ProgressDialog(Updateproduction.this);
mDiaglog.setMessage("Please Waiting...");
mDiaglog.show();
table_user.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
//if(dataSnapshot.child(spinnershift.getSelectedItem()
.toString()).exists())
// {
// mDiaglog.dismiss();
// Toast.makeText(Updatecustomer.this, "Data
already Stored", Toast.LENGTH_SHORT).show();
// }
// else
{
mDiaglog.dismiss();
Datastore user = new
Datastore(datepickerfr.getText().toString(),datepickerto.getText()
.toString(),
edtpho.getText().toString().trim(),
edtname.getText().toString().trim());
listref =
childref.child(datepickerfr.getText().toString());
noderef =
listref.child(edtname.getText().toString());
noderef.setValue(user);
//Intent addintent = new
Intent(MainActivity.this,Paid.class);
// startActivity(addintent);
Toast.makeText(Updatecustomer.this, "Data saved
successfully !", Toast.LENGTH_SHORT).show();
finish();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home){
this.finish();
}
return super.onOptionsItemSelected(item);
}
}
activity_update_customer.xml
<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="match_parent"
tools:context="com.udayaj.rajadriving.Updatecustomer">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Raja Driving School"
android:textStyle="bold"
android:textColor="#f05"
android:textSize="25dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:id="#+id/textView" />
<EditText
android:id="#+id/edtname"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="#+id/datepickerfr"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:hint="Enter Customer Name"
android:inputType="textPersonName"
android:textSize="16dp" />
<EditText
android:id="#+id/edtpho"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/edtname"
android:layout_below="#+id/edtname"
android:layout_marginTop="19dp"
android:hint="Enter Phone No."
android:inputType="number"
android:minLines="10"/>
<Button
android:id="#+id/btnsubmit"
android:layout_width="150dp"
android:layout_height="55dp"
android:layout_below="#+id/edtpho"
android:layout_centerHorizontal="true"
android:layout_marginTop="96dp"
android:background="#drawable/sty_submit"
android:text="Submit"
android:textColor="#android:color/white" />
<EditText
android:id="#+id/datepickerfr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView5"
android:layout_marginEnd="19dp"
android:layout_toStartOf="#+id/datepickerto"
android:hint="Enter From Date"
android:inputType="date" />
<EditText
android:id="#+id/datepickerto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/textView5"
android:layout_marginEnd="42dp"
android:hint="Enter Expire Date"
android:inputType="date" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="Date use this format eg:6-6-2018."
android:id="#+id/textView5" />
</RelativeLayout>

Related

Reading Selected Date without DatePickeView in android studio

I am Parvanshu Sharma and I am a beginner to programming, I am making an application in which
I have done that on button click a date Picker dialog will appear and the button text will be set to the selected by the user, Currently there are 3 buttons for this and I even have a realtime database for uploading this date on Firebase, but now I am having problems in getting the every unique date and uploading it, I am not able to get the selected date.
And as my every stackoverflow question has-
MainActivity.java (Its too big so I haven't shown imports)
public class MainActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, AdapterView.OnItemSelectedListener {
String CurrentDateString;
TextView mainDate;
Integer OrderQuantity = 3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button SelectDate1 = findViewById(R.id.SelectDateButton1);
Button SelectDate2 = findViewById(R.id.SelectDateButton2);
Button SelectDate3 = findViewById(R.id.SelectDateButton3);
SelectDate1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DialogFragment datePicker = new DatePickerFragment();
datePicker.show(getSupportFragmentManager(), "Pick item order date");
mainDate = SelectDate1;
}
});
SelectDate2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DialogFragment datePicker = new DatePickerFragment();
datePicker.show(getSupportFragmentManager(), "Pick item order date");
mainDate = SelectDate2;
}
});
SelectDate3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DialogFragment datePicker = new DatePickerFragment();
datePicker.show(getSupportFragmentManager(), "Pick item order date");
mainDate = SelectDate3;
}
});
ArrayAdapter<CharSequence> FoodAdapter = ArrayAdapter.createFromResource(this, R.array.FoodList, android.R.layout.simple_spinner_item);
FoodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner SelectItem1 = findViewById(R.id.SelectItem1);
SelectItem1.setAdapter(FoodAdapter);
SelectItem1.setOnItemSelectedListener(this);
Spinner SelectItem2 = findViewById(R.id.SelectItem2);
SelectItem2.setAdapter(FoodAdapter);
SelectItem2.setOnItemSelectedListener(this);
Spinner SelectItem3 = findViewById(R.id.SelectItem3);
SelectItem3.setAdapter(FoodAdapter);
SelectItem3.setOnItemSelectedListener(this);
ArrayAdapter<CharSequence> QuantityAdapter = ArrayAdapter.createFromResource(this, R.array.Quantity, android.R.layout.simple_spinner_item);
QuantityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner Quantity1 = findViewById(R.id.SelectQuantity1);
Quantity1.setAdapter(QuantityAdapter);
Quantity1.setOnItemSelectedListener(this);
Spinner Quantity2 = findViewById(R.id.SelectQuantity2);
Quantity2.setAdapter(QuantityAdapter);
Quantity2.setOnItemSelectedListener(this);
Spinner Quantity3 = findViewById(R.id.SelectQuantity3);
Quantity3.setAdapter(QuantityAdapter);
Quantity3.setOnItemSelectedListener(this);
Button DoneButton = findViewById(R.id.DoneButton);
EditText PersonName = findViewById(R.id.PersonName);
EditText PersonPhone = findViewById(R.id.PersonPhone);
EditText PersonAddress = findViewById(R.id.PersonAddress);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DoneButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DatabaseReference Name = database.getReference(PersonPhone.getText().toString() + "/Name");
Name.setValue(PersonName.getText().toString());
DatabaseReference Phone = database.getReference(PersonPhone.getText().toString() + "/Phone");
Phone.setValue(PersonPhone.getText().toString());
DatabaseReference Address = database.getReference(PersonPhone.getText().toString() + "/Address");
Address.setValue(PersonAddress.getText().toString());
if (Quantity1.getSelectedItem().toString().equals("0")) {
OrderQuantity -= 1;
}
if (Quantity2.getSelectedItem().toString().equals("0")) {
OrderQuantity -= 1;
}
if (Quantity3.getSelectedItem().toString().equals("0")) {
OrderQuantity -= 1;
}
DatabaseReference OrderQuantities = database.getReference(PersonPhone.getText().toString()+"/OrderQuantity");
OrderQuantities.setValue(OrderQuantity);
if (Quantity1.getSelectedItem().toString() != "0") {
//I want some solution HERE
}
}
});
}
#Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
String CurrentDateString = format.format(c.getTime());
mainDate.setText(CurrentDateString);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
}```
and here goes my activity_main.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"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/NameTextView"
android:layout_width="93dp"
android:layout_height="wrap_content"
android:layout_marginStart="20sp"
android:layout_marginLeft="20sp"
android:layout_marginTop="10sp"
android:text="Name"
android:textColor="#color/black"
android:textSize="28sp"
android:textStyle="bold" />
<EditText
android:id="#+id/PersonName"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_marginStart="20sp"
android:layout_marginLeft="20sp"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName" />
<TextView
android:id="#+id/PhoneTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:text="Mobile Number"
android:textColor="#color/black"
android:textSize="28sp"
android:textStyle="bold" />
<EditText
android:id="#+id/PersonPhone"
android:layout_width="325dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:ems="10"
android:hint="Mobile number"
android:inputType="phone" />
<TextView
android:id="#+id/AddressTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:text="Address"
android:textColor="#color/black"
android:textSize="28sp"
android:textStyle="bold" />
<EditText
android:id="#+id/PersonAddress"
android:layout_width="328dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:ems="10"
android:hint="Delivery Address"
android:inputType="textPostalAddress" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:text=" Order Details"
android:textColor="#color/black"
android:textSize="20sp"
android:textStyle="bold" />
<TableLayout
android:id="#+id/MainTable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:stretchColumns="0,1,2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#000000"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text=" Date "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Item"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Quantity"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#000000">
<Button
android:id="#+id/SelectDateButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select" />
<Spinner
android:id="#+id/SelectItem1"
android:layout_width="40dp"
android:layout_height="43dp"
android:layout_marginStart="3dp"
android:layout_marginLeft="3dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:background="#color/white"
android:gravity="center"
android:text="Select Item" />
<Spinner
android:id="#+id/SelectQuantity1"
android:layout_width="40dp"
android:layout_height="43dp"
android:background="#color/white"
android:gravity="center" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#000000">
<Button
android:id="#+id/SelectDateButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select" />
<Spinner
android:id="#+id/SelectItem2"
android:layout_width="40dp"
android:layout_height="43dp"
android:layout_marginStart="3dp"
android:layout_marginLeft="3dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:background="#color/white"
android:gravity="center"
android:text="Select Item" />
<Spinner
android:id="#+id/SelectQuantity2"
android:layout_width="40dp"
android:layout_height="43dp"
android:background="#color/white"
android:gravity="center" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#000000">
<Button
android:id="#+id/SelectDateButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select" />
<Spinner
android:id="#+id/SelectItem3"
android:layout_width="40dp"
android:layout_height="43dp"
android:layout_marginStart="3dp"
android:layout_marginLeft="3dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:background="#color/white"
android:gravity="center" />
<Spinner
android:id="#+id/SelectQuantity3"
android:layout_width="40dp"
android:layout_height="43dp"
android:background="#color/white"
android:gravity="center" />
</TableRow>
</TableLayout>
<Button
android:id="#+id/DoneButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Done" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
and I have one more class for creating DatePickerDialog,
the source from where I learnt and implemented that how to make DatePickerDialog is Here
which goes here- (DatePickerFragment.java)
public class DatePickerFragment extends DialogFragment {
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), (DatePickerDialog.OnDateSetListener) getActivity(), year, month, day);
}
}
Tried using an interface. You will have all 3 dates in your main activity, now you can do whatever with them
public class DatePickerFragment extends DialogFragment {
private static applyDate mInterface;
private static int buttonNumberHere;
public interface applyDate {
void setDate(int selectedYear, int selectedMonth, int selectedDay, int buttonNumber);
}
public static DatePickerFragment newInstance(int buttonNumber, applyDate context)
{
DatePickerFragment fragment = new DatePickerFragment();
mInterface = ((applyDate) context);
buttonNumberHere = buttonNumber;
return fragment;
}
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getContext(), datePickerListener, year, month, day);
}
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
mInterface.setDate(selectedYear, selectedMonth, selectedDay, buttonNumberHere);
}
};
In MainActivity
public class MainActivity extends AppCompatActivity implements applyDate, AdapterView.OnItemSelectedListener {
String CurrentDateString;
TextView mainDate;// Idk what is this
Integer OrderQuantity = 3;
String itemOneDate;
String itemTwoDate;
String itemThreeDate;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button SelectDate1 = findViewById(R.id.SelectDateButton1);
Button SelectDate2 = findViewById(R.id.SelectDateButton2);
Button SelectDate3 = findViewById(R.id.SelectDateButton3);
SelectDate1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DatePickerFragment datePicker = DatePickerFragment.newInstance(1, MainActivity.this);
datePicker.show(getSupportFragmentManager(), "Pick item order date");
mainDate = SelectDate1;
}
});
SelectDate2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DatePickerFragment datePicker = DatePickerFragment.newInstance(2, MainActivity.this);
datePicker.show(getSupportFragmentManager(), "Pick item order date");
mainDate = SelectDate2;
}
});
SelectDate3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DatePickerFragment datePicker = DatePickerFragment.newInstance(3, MainActivity.this);
datePicker.show(getSupportFragmentManager(), "Pick item order date");
mainDate = SelectDate3;
}
});
ArrayAdapter<CharSequence> FoodAdapter = ArrayAdapter.createFromResource(this, R.array.FoodList, android.R.layout.simple_spinner_item);
FoodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner SelectItem1 = findViewById(R.id.SelectItem1);
SelectItem1.setAdapter(FoodAdapter);
SelectItem1.setOnItemSelectedListener(this);
Spinner SelectItem2 = findViewById(R.id.SelectItem2);
SelectItem2.setAdapter(FoodAdapter);
SelectItem2.setOnItemSelectedListener(this);
Spinner SelectItem3 = findViewById(R.id.SelectItem3);
SelectItem3.setAdapter(FoodAdapter);
SelectItem3.setOnItemSelectedListener(this);
ArrayAdapter<CharSequence> QuantityAdapter = ArrayAdapter.createFromResource(this, R.array.Quantity, android.R.layout.simple_spinner_item);
QuantityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner Quantity1 = findViewById(R.id.SelectQuantity1);
Quantity1.setAdapter(QuantityAdapter);
Quantity1.setOnItemSelectedListener(this);
Spinner Quantity2 = findViewById(R.id.SelectQuantity2);
Quantity2.setAdapter(QuantityAdapter);
Quantity2.setOnItemSelectedListener(this);
Spinner Quantity3 = findViewById(R.id.SelectQuantity3);
Quantity3.setAdapter(QuantityAdapter);
Quantity3.setOnItemSelectedListener(this);
Button DoneButton = findViewById(R.id.DoneButton);
EditText PersonName = findViewById(R.id.PersonName);
EditText PersonPhone = findViewById(R.id.PersonPhone);
EditText PersonAddress = findViewById(R.id.PersonAddress);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DoneButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Idk how to set date but now you have all three dates
DatabaseReference dateOne = database.getReference(itemOneDate + "/DateOne");
dateOne.setValue(itemOneDate);
DatabaseReference dateTwo = database.getReference(itemOneDate + "/DateTwo");
dateTwo.setValue(itemTwoDate);
DatabaseReference dateThree = database.getReference(itemThreeDate + "/DateThree");
dateThree.setValue(itemThreeDate);
DatabaseReference Name = database.getReference(PersonPhone.getText().toString() + "/Name");
Name.setValue(PersonName.getText().toString());
DatabaseReference Phone = database.getReference(PersonPhone.getText().toString() + "/Phone");
Phone.setValue(PersonPhone.getText().toString());
DatabaseReference Address = database.getReference(PersonPhone.getText().toString() + "/Address");
Address.setValue(PersonAddress.getText().toString());
if (Quantity1.getSelectedItem().toString().equals("0")) {
OrderQuantity -= 1;
}
if (Quantity2.getSelectedItem().toString().equals("0")) {
OrderQuantity -= 1;
}
if (Quantity3.getSelectedItem().toString().equals("0")) {
OrderQuantity -= 1;
}
DatabaseReference OrderQuantities = database.getReference(PersonPhone.getText().toString()+"/OrderQuantity");
OrderQuantities.setValue(OrderQuantity);
if (Quantity1.getSelectedItem().toString() != "0") {
//I want some solution HERE
}
}
});
}
#Override
public void setDate(int selectedYear, int selectedMonth, int selectedDay, int buttonNumber){
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, selectedYear);
c.set(Calendar.MONTH, selectedMonth);
c.set(Calendar.DAY_OF_MONTH, selectedDay);
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
String CurrentDateString = format.format(c.getTime());
mainDate.setText(CurrentDateString);
if (buttonNumber == 1){
itemOneDate = CurrentDateString;
}
else if (buttonNumber == 2){
itemTwoDate = CurrentDateString;
}
else if (buttonNumber == 3){
itemThreeDate = CurrentDateString;
}
}
}

Recyclerview is Scrolling when media Player is playing. How can i fix it?

I'm developing a ChatApp with the function of Audio Messages. The Recording and playing of this Audio Messages are working very well, but if i click on Play Button the Recyclerview is scrolling up. Anyone have an idea?
Sorry for my bad english, i'm from Germany ;)
AdapterChat.Java
private static final int MSG_TYPE_LEFT = 0;
private static final int MSG_TYPE_RIGHT = 1;
Context context;
List<ModelChat> chatList;
String imageUrl;
FirebaseUser fUser;
public AdapterChat(Context context, List<ModelChat> chatList, String imageUrl) {
this.context = context;
this.chatList = chatList;
this.imageUrl = imageUrl;
}
#NonNull
#Override
public MyHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
//inflate layouts: row_chat_left.xml for receiver, row_chat_right.xml for sender
if (i == MSG_TYPE_RIGHT) {
View view = LayoutInflater.from(context).inflate(R.layout.row_chat_right, viewGroup, false);
return new MyHolder(view);
}
else {
View view = LayoutInflater.from(context).inflate(R.layout.row_chat_left, viewGroup, false);
return new MyHolder(view);
}
}
public void add(ModelChat object) {
chatList.add(object);
add(object);
}
#SuppressLint("ClickableViewAccessibility")
#Override
public void onBindViewHolder(#NonNull final MyHolder myHolder, final int i) {
final String message = chatList.get(i).getMessage();
String timeStamp = chatList.get(i).getTimestamp();
String type = chatList.get(i).getType();
if (type.equals("text") || message.equals(R.string.message_was_deleted)) {
//text message
myHolder.messageTv.setVisibility(View.VISIBLE);
myHolder.messageIv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.GONE);
myHolder.messageVoiceSb.setVisibility(View.GONE);
myHolder.sbCurrentTime.setVisibility(View.GONE);
myHolder.sbTotalDuration.setVisibility(View.GONE);
myHolder.messageTv.setText(message);
}
else if (type.equals("audio")) {
//audio message
myHolder.messageTv.setVisibility(View.GONE);
myHolder.messageIv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.VISIBLE);
myHolder.messageVoiceSb.setVisibility(View.VISIBLE);
myHolder.sbCurrentTime.setVisibility(View.VISIBLE);
myHolder.sbTotalDuration.setVisibility(View.VISIBLE);
myHolder.voiceMessageUrl = message;
myHolder.getAdapterPosition();
myHolder.playAudioBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (myHolder.mediaPlayer.isPlaying()) {
myHolder.handler.removeCallbacks(myHolder.updater);
myHolder.mediaPlayer.pause();
myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
}
else {
myHolder.mediaPlayer.start();
myHolder.playAudioBtn.setImageResource(R.drawable.ic_pause_btn);
myHolder.updateSeekbar();
}
}
});
myHolder.prepareMediaPlayer();
myHolder.messageVoiceSb.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
SeekBar seekBar = (SeekBar) view;
int playPosition = (myHolder.mediaPlayer.getDuration() / 100) * seekBar.getProgress();
myHolder.mediaPlayer.seekTo(playPosition);
myHolder.sbCurrentTime.setText(myHolder.milliSecondsToTimer(myHolder.mediaPlayer.getCurrentPosition()));
return false;
}
});
myHolder.mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
#Override
public void onBufferingUpdate(MediaPlayer mediaPlayer, int i) {
myHolder.messageVoiceSb.setSecondaryProgress(i);
}
});
myHolder.mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
myHolder.messageVoiceSb.setProgress(0);
myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
myHolder.mediaPlayer.reset();
myHolder.prepareMediaPlayer();
}
});
}
else {
//image message
myHolder.messageIv.setVisibility(View.VISIBLE);
myHolder.messageTv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.GONE);
myHolder.messageVoiceSb.setVisibility(View.GONE);
myHolder.sbCurrentTime.setVisibility(View.GONE);
myHolder.sbTotalDuration.setVisibility(View.GONE);
Picasso.get().load(message).placeholder(R.drawable.ic_image_black).into(myHolder.messageIv);
}
//set data
myHolder.messageTv.setText(message);
myHolder.timeTv.setText(timeStamp);
try {
Picasso.get().load(imageUrl).into(myHolder.profileIv);
}
catch (Exception e) {
}
myHolder.messageLayout.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
//show delete message confirm dialog
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.delete);
builder.setMessage("Are you sure to delete this message?");
//delete button
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
deleteMessage(i);
}
});
//cancel delete button
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//dismiss dialog
dialog.dismiss();
}
});
//create and show dialog
builder.create().show();
return false;
}
});
//set seen/delivered status of message
if (i==chatList.size()-1) {
if (chatList.get(i).isSeen()) {
myHolder.isSeenTv.setText("Seen");
}
else {
myHolder.isSeenTv.setText("Delivered");
}
}
else {
myHolder.isSeenTv.setVisibility(View.GONE);
}
}
private void deleteMessage(int position) {
final String myUID = FirebaseAuth.getInstance().getCurrentUser().getUid();
/*Logic:
* Get timeStamp of clicked message
* Compare the timeStamp of the clicked message with all messages in CHats
* Where both values matches, delete that message
* This will allow sender to delete his and receiver's message*/
String msgTimeStamp = chatList.get(position).getTimestamp();
final String type = chatList.get(position).getType();
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("Chats");
Query query = dbRef.orderByChild("timestamp").equalTo(msgTimeStamp);
query.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds: dataSnapshot.getChildren()) {
/*if you want to allow sender to delete only his message then
* compare sender value with current user's uid
* if they match means its the message of sender that is trying to delete*/
if (ds.child("sender").getValue().equals(myUID)) {
if (type.equals("audio")) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("type", "text");
ds.getRef().updateChildren(hashMap);
} else if (type.equals("image")) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("type", "text");
ds.getRef().updateChildren(hashMap);
}
/*We can do one of two things here
* 1) Remove the message from chats
* 2) Set the value of message "This messages was deleted..." */
//1) Remove the message from Chats
//ds.getRef().removeValue();
//2) Set the value of message "This message was deleted..."
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("message", "This message was deleted...");
ds.getRef().updateChildren(hashMap);
Toast.makeText(context, "message deleted...", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(context, "You can delete only your messages...", Toast.LENGTH_SHORT).show();
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
#Override
public int getItemCount() {
return chatList.size();
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public int getItemViewType(int position) {
//get currently signed in user
fUser = FirebaseAuth.getInstance().getCurrentUser();
if (chatList.get(position).getSender().equals(fUser.getUid())) {
return MSG_TYPE_RIGHT;
}
else {
return MSG_TYPE_LEFT;
}
}
//view holder class
class MyHolder extends RecyclerView.ViewHolder {
//views
ImageView profileIv, messageIv;
ImageButton playAudioBtn;
SeekBar messageVoiceSb;
TextView messageTv, timeTv, isSeenTv, sbCurrentTime, sbTotalDuration;
LinearLayout messageLayout; //for click listener to show delete option
MediaPlayer mediaPlayer;
Handler handler = new Handler();
String voiceMessageUrl = null;
#SuppressLint("ClickableViewAccessibility")
public MyHolder(#NonNull View itemView) {
super(itemView);
//init views
profileIv = itemView.findViewById(R.id.profileIv);
messageIv = itemView.findViewById(R.id.messageIV);
messageTv = itemView.findViewById(R.id.messageTv);
messageVoiceSb = itemView.findViewById(R.id.messageVoiceSb);
playAudioBtn = itemView.findViewById(R.id.playAudioBtn);
sbCurrentTime = itemView.findViewById(R.id.sbCurrentTime);
sbTotalDuration = itemView.findViewById(R.id.sbTotalDuration);
timeTv = itemView.findViewById(R.id.timeTv);
isSeenTv = itemView.findViewById(R.id.isSeenTv);
messageLayout = itemView.findViewById(R.id.messageLayout);
mediaPlayer = new MediaPlayer();
messageVoiceSb.setMax(100);
}
private void prepareMediaPlayer() {
try {
mediaPlayer.setDataSource(voiceMessageUrl); //url of audio file to play
mediaPlayer.prepare();
sbTotalDuration.setText(milliSecondsToTimer(mediaPlayer.getDuration()));
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
private Runnable updater = new Runnable() {
#Override
public void run() {
updateSeekbar();
long currentDuration = mediaPlayer.getCurrentPosition();
sbCurrentTime.setText(milliSecondsToTimer(currentDuration));
}
};
private void updateSeekbar() {
if (mediaPlayer.isPlaying()) {
messageVoiceSb.setProgress((int) (((float) mediaPlayer.getCurrentPosition() / mediaPlayer.getDuration()) * 100));
handler.postDelayed(updater, 1000);
}
}
private String milliSecondsToTimer(long milliSeconds) {
String timerString = "";
String secondsString;
int hours = (int) (milliSeconds / (1000 * 60 * 60));
int minutes = (int) (milliSeconds % (1000 * 60 * 60)) / (1000 * 60);
int seconds = (int) ((milliSeconds % (1000 * 60 * 60)) % (1000 * 60) / 1000);
if (hours > 0) {
timerString = hours + ":";
}
if (seconds < 10) {
secondsString = "0" + seconds;
} else {
secondsString = "" + seconds;
}
timerString = timerString + minutes + ":" + secondsString;
return timerString;
}
}
chatActivity.xml
<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="match_parent"
android:background="#color/chatBackground"
tools:context=".ChatActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/colorPrimaryDark"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profileIv"
android:layout_width="35dp"
android:layout_height="35dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_default"
app:civ_circle_background_color="#color/colorPrimaryDark"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_marginStart="20dp">
<!-- Receiver Name-->
<TextView
android:id="#+id/nameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="His Name"
android:textColor="#color/colorWhite"
android:textSize="18sp"
android:textStyle="bold" />
<!-- Receiver Status i.e online or offline-->
<TextView
android:id="#+id/userStatusTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="online"
android:textColor="#color/colorWhite"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/blockIv"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:src="#drawable/ic_unblocked_green"
android:visibility="invisible"/>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
<!-- RecyclerView-->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/chat_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:layout_above="#id/chatLayout" />
<!-- send message edit text and button in layout-->
<LinearLayout
android:id="#+id/chatLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="#color/textInputBackground"
android:orientation="horizontal">
<!-- ImageButton: to send Image-->
<ImageButton
android:id="#+id/attachBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#null"
android:src="#drawable/ic_attach_black" />
<!-- EditText: input message-->
<EditText
android:id="#+id/messageEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:inputType="textCapSentences|textMultiLine"
android:padding="15dp"
android:hint="Start typing" />
<Chronometer
android:id="#+id/record_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textSize="14sp"
android:textColor="#color/colorPrimary" />
<!-- Button: voice message-->
<ImageButton
android:id="#+id/recordBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:src="#drawable/ic_record_btn_stopped" />
<!-- Button: send message-->
<ImageButton
android:id="#+id/sendBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:src="#drawable/ic_send" />
</LinearLayout>
row_chat_right.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/messageLayout"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="end">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/profileIv"
app:civ_border_color="#null"
android:visibility="gone"
android:src="#drawable/ic_default_img" />
<TextView
android:id="#+id/messageTv"
android:layout_weight="1"
android:textSize="16sp"
android:textColor="#color/textColor"
android:background="#drawable/bg_sender"
android:padding="15dp"
android:text="His Message"
android:visibility="gone"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/messageIV"
android:layout_width="200dp"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:padding="15dp"
android:src="#drawable/ic_image_black"
android:scaleType="fitCenter"
android:background="#drawable/bg_sender" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_sender"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/playAudioBtn"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:background="#null"
android:src="#drawable/ic_play_btn" />
<SeekBar
android:id="#+id/messageVoiceSb"
android:visibility="gone"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/playAudioBtn"
android:padding="10dp"
android:layout_marginTop="10dp"
android:max="100"
android:progress="0" />
<TextView
android:id="#+id/sbCurrentTime"
android:visibility="gone"
android:text="0:00"
android:textStyle="bold"
android:textSize="12sp"
android:layout_marginStart="2dp"
android:layout_below="#id/messageVoiceSb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/sbTotalDuration"
android:visibility="gone"
android:textStyle="bold"
android:text="0:10"
android:textSize="12sp"
android:layout_below="#id/messageVoiceSb"
android:layout_toEndOf="#id/messageVoiceSb"
android:layout_marginEnd="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
<TextView
android:id="#+id/timeTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textAlignment="textEnd"
android:text="07/08/2020 23:00PM"
android:textColor="#color/textColor"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/isSeenTv"
android:gravity="end"
android:textAlignment="textEnd"
android:text="delivered" />
Here is the Fix!!
<TextView
android:layout_width="match_parent" <-- This is what I changed
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent" <-- Check this as well
android:layout_height="wrap_content"/>

Country code is not getting from country code picker in Android

I am developing an signup activity in android app. I want show the country telephone code(get the country from device). It may show the list of countries containing with flag, country telephone code, country name. I get the code of country code picker from https://github.com/mukeshsolanki/country-picker-android . It contain the complete code. I want to set the default country is in the phone.
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
System.out.println("country = "+country);
When i using this code i get the country code "in". But i want to display telephone code and flag, name. When i open the screen. I want to display it automatically.
My code is shown below
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/colorBackground"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="56dp"
android:paddingLeft="24dp"
android:paddingRight="24dp">
<ImageView
android:background="#drawable/logo"
android:layout_gravity="center_horizontal"
android:layout_width="150dp"
android:layout_height="150dp" />
<Button
android:text="Country"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/buttonCountry" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:backgroundTint="#d11f08"
android:entries="#array/android_dropdown_arrays"
android:padding="5dp" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="#+id/editTextPhone"
android:layout_width="match_parent"
android:layout_height="44dp"
android:inputType="phone"
android:hint="Password"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/buttonSubmit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:textColor="#color/colorAccent"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:padding="12dp"
android:text="Login"/>
</LinearLayout>
</ScrollView>
Main.Activity
public class MainActivity extends AppCompatActivity {
EditText editText;
Button button;
Button buttonCountry;
private Spinner spinner1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editTextPhone);
button = (Button) findViewById(R.id.buttonSubmit);
buttonCountry = (Button) findViewById(R.id.buttonCountry);
spinner1 = (Spinner) findViewById(R.id.spinner1);
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
System.out.println("country = "+countryCodeValue);
//String mPhoneNumber = tm.getLine1Number(); //not getting phone number
//System.out.println("phone no = "+mPhoneNumber);
buttonCountry.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
spinner1.setOnItemSelectedListener(new ItemSelectedListener());
final CountryPicker picker = CountryPicker.newInstance("Select Country");
picker.show(getSupportFragmentManager(), "COUNTRY_PICKER");
picker.setListener(new CountryPickerListener() {
#Override
public void onSelectCountry(String name, String code, String dialCode, int flagDrawableResID) {
// Implement your code here
Log.d("LOGTAG", "output1 : name = "+name+" code = "+code+" dialcode = "+dialCode+" flag = "+flagDrawableResID);
picker.dismiss();
}
});
}
});
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
public class ItemSelectedListener implements AdapterView.OnItemSelectedListener {
//get strings of first item
String firstItem = String.valueOf(spinner1.getSelectedItem());
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if (firstItem.equals(String.valueOf(spinner1.getSelectedItem()))) {
// ToDo when first item is selected
} else {
Toast.makeText(parent.getContext(),
"You have selected : " + parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_LONG).show();
// Todo when item is selected by the user
}
}
#Override
public void onNothingSelected(AdapterView<?> arg) {
}
}
}
Reference : https://github.com/hbb20/CountryCodePickerProject
try to get country code using Lat, long
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addressList = geocoder.getFromLocation(
lati, longi, 1); // lati : Latitude ,longi : Longitude
if (addressList != null && addressList.size() > 0) {
Address address = addressList.get(0);
code=addressList.get(0).getCountryCode();
System.out.println("code :: "+addressList.get(0).getCountryCode());
}
} catch (IOException e) {
Log.e(TAG, "Unable connect to Geocoder", e);
}
String locale = context.getResources().getConfiguration().locale.getCountry();
You can use this library
Click here
by then you can do this
new DialogPlusBuilder().blurBackground()
.buildCountriesListDialog(true,new DialogPlus.CountriesDialogListener() {
#Override
public void onItemClicked(CountryDataModel countryDataModel, DialogPlus dialogPlus) {
super.onItemClicked(countryDataModel, dialogPlus);
Toast.makeText(MainActivity.this,countryDataModel.getName()+ countryDataModel.getPhone_code(), Toast.LENGTH_SHORT).show();
}
})
.show(this.getSupportFragmentManager(), "Countries List Dialog");

Validate the field in recyler view android

I need to validate the each field inside recylerview. I didn't find the best approach to perform the validation. The each Edittext field need to validation if the value is empty.Show the toast message on each empty value
Custom XML File
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/carview_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="#+id/ET_CT_foodeaten"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Food Eaten"
android:imeActionLabel="Food Eaten"
android:imeOptions="actionUnspecified"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/rel_serving"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linear_ser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="#dimen/carview_margin"
android:text="Servings Eaten"
android:textSize="18dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-10dp"
android:background="#drawable/linear_layout_radius_custom"
android:orientation="horizontal">
<ImageView
android:layout_width="60sp"
android:id="#+id/minus_foodeaten"
android:layout_height="50sp"
android:padding="#dimen/carview_margin"
android:src="#drawable/minus" />
<View
android:layout_width="1dp"
android:layout_height="35sp"
android:layout_gravity="center"
android:background="#color/TabHeaderColor" />
<ImageView
android:layout_width="60sp"
android:layout_height="50sp"
android:id="#+id/add_foodeaten"
android:padding="#dimen/carview_margin"
android:src="#drawable/ic_add" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/linear_ser"
android:orientation="vertical">
<ImageView
android:id="#+id/IMG_info"
android:layout_width="wrap_content"
android:layout_marginRight="15dp"
android:layout_height="wrap_content"
android:src="#drawable/info" />
<TextView
android:id="#+id/value_serving"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="15dp"
android:text="0"
android:textSize="18dp" />
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="1dp"
android:id="#+id/space_view"
android:layout_height="80sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#color/TabHeaderColor" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/rel_serving">
<TextView
android:id="#+id/label_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:layout_margin="#dimen/carview_margin"
android:text="Food Group"
android:textSize="18dp" />
<Spinner
android:id="#+id/CS_food_group_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/label_food"
android:layout_margin="#dimen/carview_margin"
android:drawSelectorOnTop="true"
android:spinnerMode="dropdown" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Adapter code
public class CustomDataAdapterRecylerview extends RecyclerView.Adapter {
private List values;
private Activity activity;
AlertDialog alertDialogStores;
String[] foodLists;
FoodList[] val_list;
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
FoodList food_list_value;
public CustomDataAdapterRecylerview(List<String> values, Activity context) {
this.values = values;
this.activity = context;
}
#Override
public CustomDataAdapterRecylerview.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.edittext_twospinner, viewGroup, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
final ViewHolder holder = viewHolder;
final int pos = position;
viewHolder.info.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showPopUp();
}
});
final ArrayAdapter<CharSequence> foodGroup_adapter = ArrayAdapter.createFromResource(activity, R.array.Food_Group, android.R.layout.simple_spinner_item);
foodGroup_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
viewHolder.FoodGroup_spinner.setAdapter(foodGroup_adapter);
foodLists = new String[100];
val_list = new FoodList[100];
food_list_value = new FoodList();
viewHolder.FoodGroup_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
food_list_value.setServingsEaten(parent.getItemAtPosition(position).toString());
SingletonAddValueFoodTracker.getInstance().setList_values(val_list);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
viewHolder.setClickListener(new RecyclerViewItemClickListener() {
#Override
public void onClick(View view, int position, boolean isLongClick) {
if (view.getId() == holder.Add_Food_Item.getId()) {
int val = Integer.parseInt(holder.valueserving.getText().toString());
if (val < 15) {
val++;
food_list_value.setServingsEaten(String.valueOf(val));
SingletonAddValueFoodTracker.getInstance().setList_values(val_list);
}
holder.valueserving.setText(String.valueOf(val));
} else if (view.getId() == holder.Minus_Food_Item.getId()) {
int val = Integer.parseInt(holder.valueserving.getText().toString());
if (val != 0) {
val--;
food_list_value.setServingsEaten(String.valueOf(val));
SingletonAddValueFoodTracker.getInstance().setList_values(val_list);
}
holder.valueserving.setText(String.valueOf(val));
}
{
//Toast.makeText(view.getContext(), "ROW PRESSED = " + String.valueOf(position), Toast.LENGTH_SHORT).show();
}
}
});
viewHolder.Food_Eaten.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
foodLists[pos] = String.valueOf(s);
food_list_value.setFoodEaten(foodLists[pos]);
val_list[pos] = food_list_value;
SingletonAddValueFoodTracker.getInstance().setList_values(val_list);
}
});
}
#Override
public int getItemCount() {
return values.size();
}
public void addItem(String country) {
values.add(country);
notifyItemInserted(values.size());
}
public void removeItem(int position) {
values.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, values.size());
}
private void showPopUp() {
// add your items, this can be done programatically
// your items can be from a database
List<FoodTrackerAlertDialogModel> ObjectItemData = new ArrayList<FoodTrackerAlertDialogModel>();
ObjectItemData.add(new FoodTrackerAlertDialogModel("Fruit", "1 medium-sized piece of fruit", "1/2 cup berries", "3/4 cup fruit/veggie juice"));
ObjectItemData.add(new FoodTrackerAlertDialogModel("Vege\ntables", "1/2 cup raw not-leafy veggies", "1 cup raw leafy veggies", "1 small baked potato"));
ObjectItemData.add(new FoodTrackerAlertDialogModel("Dairy", "8 ounces milk", "1 cup yogurt", "1/2 ounces of cheese"));
ObjectItemData.add(new FoodTrackerAlertDialogModel("Grains", "1 slice bread", "1 ounce dry cereal", "1/2 cup cooked rice or pasta"));
ObjectItemData.add(new FoodTrackerAlertDialogModel("Lean\nMeat\nPoultry", "3 ounces cooked lean meat", "skinless poultry (about the size of a deck of cards)", "1 egg"));
ObjectItemData.add(new FoodTrackerAlertDialogModel("Fish", "", "2 to 3 oz. (about the size of the palm of a woman&apos;s hand)", ""));
ObjectItemData.add(new FoodTrackerAlertDialogModel("Snacks", "15 potato chips", "2 small cookies", "1/2 cup ice cream"));
ObjectItemData.add(new FoodTrackerAlertDialogModel("Fats\nOils", "2 tablespoons light salad dressing", "1 tablespoon low-fat margarine or mayonnaise", "1 teaspoon vegetable oil"));
// our adapter instance
ListViewArrayAdapter adapter = new ListViewArrayAdapter(activity, R.layout.listview_fourtextview, ObjectItemData);
// create a new ListView, set the adapter and item click listener
ListView listViewItems = new ListView(activity);
listViewItems.setAdapter(adapter);
//listViewItems.setOnItemClickListener(new OnItemClickListenerListViewItem());
// put the ListView in the pop up
alertDialogStores = new AlertDialog.Builder(activity)
.setView(listViewItems)
.setTitle("Examples of what a serving\n").setPositiveButton("Back", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
alertDialogStores.dismiss();
}
})
.show();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
EditText Food_Eaten;
ImageView info, Add_Food_Item, Minus_Food_Item;
Spinner FoodGroup_spinner;
TextView valueserving;
private RecyclerViewItemClickListener clickListener;
public ViewHolder(View view) {
super(view);
info = (ImageView) view.findViewById(R.id.IMG_info);
Food_Eaten = (EditText) view.findViewById(R.id.ET_CT_foodeaten);
FoodGroup_spinner = (Spinner) view.findViewById(R.id.CS_food_group_spinner);
valueserving = (TextView) view.findViewById(R.id.value_serving);
Add_Food_Item = (ImageView) view.findViewById(R.id.add_foodeaten);
Minus_Food_Item = (ImageView) view.findViewById(R.id.minus_foodeaten);
view.setOnClickListener(this);
view.setOnLongClickListener(this);
Add_Food_Item.setOnClickListener(this);
Minus_Food_Item.setOnClickListener(this);
}
public void setClickListener(RecyclerViewItemClickListener recyclerViewItemClickListener) {
this.clickListener = recyclerViewItemClickListener;
}
#Override
public void onClick(View v) {
clickListener.onClick(v, getPosition(), false);
}
#Override
public boolean onLongClick(View view) {
clickListener.onClick(view, getPosition(), true);
return true;
}
}
}
On click of correct icon if the edit text is empty a validation needs perform and show a toast message.
You need to use this check and print your toast in else part and your implementation in if part -
if (edittext.getText().length() > 0) {
// perform action here
} else {
// show toast here if edittext is empty
}
Hope it may be of help to you.

Cannot get values from edittext in fragment

I am new over...
My question is: how to obtain the data from the edittext in fragments? I have really tried everything I have been seeking and no result.
Here is the code:
XML Files
register_user.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include layout="#layout/toolbar"/>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/secondary_dark"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
fragment_pdata.xml
<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.fundacioncanihua.inutritionist.rnp.Fragments.PersonalDataFragment">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pData"
android:layout_marginTop="10dp"
android:textSize="40dp"
android:textStyle="bold"
android:id="#+id/textView"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/flayout_lastname"
android:theme="#style/TextLabel"
android:layout_below="#+id/textView"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_lName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/lName"
android:inputType="text"
android:maxLength="25"
android:drawableLeft="#drawable/ic_edittext_user"
android:drawablePadding="20dp"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/flayout_firstname"
android:theme="#style/TextLabel"
android:layout_below="#+id/flayout_lastname"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_fName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/fName"
android:inputType="text|textCapWords"
android:maxLength="25"
android:drawableLeft="#drawable/ic_edittext_user"
android:drawablePadding="20dp"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout android:layout_width="match_parent"
android:id="#+id/fHorizontal"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/flayout_firstname"
android:layout_marginTop="10dp">
<android.support.design.widget.TextInputLayout
android:id="#+id/flayout_birthday"
android:theme="#style/TextLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/birthday"
android:inputType="date"
android:drawableLeft="#drawable/ic_edittext_bd"
android:drawablePadding="20dp"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/flayout_gender"
android:theme="#style/TextLabel"
android:layout_width="150dp"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/gender"
android:inputType="text|textCapSentences"
android:maxLength="1"
android:drawableLeft="#drawable/ic_edittext_gender"
android:drawablePadding="20dp"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/flayout_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel"
android:layout_below="#id/fHorizontal"
android:layout_marginTop="10dp">
<EditText
android:id="#+id/input_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/location"
android:inputType="text|textCapWords"
android:maxLength="25"
android:drawableLeft="#drawable/ic_edittext_location"
android:drawablePadding="20dp"/>
</android.support.design.widget.TextInputLayout>
Java Classes
Register Patient
public class RegisterPatient extends AppCompatActivity implements PersonalDataFragment.getEditText {
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
private int[] tabIcons = {
R.drawable.ic_tab_data,
R.drawable.ic_tab_measures,
R.drawable.ic_tab_clinical
};
String s_lname;
private ConnectionSQL dataBase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register_user);
dataBase = new ConnectionSQL(getApplicationContext());
//Setting up the toolbar
Toolbar toolBar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolBar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
setupTabIcons();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.register_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case R.id.action_settings:
//Code
break;
case R.id.regbutton:
registerPatient();
break;
}
return super.onOptionsItemSelected(item);
}
private void setupTabIcons() {
tabLayout.getTabAt(0).setIcon(tabIcons[0]);
tabLayout.getTabAt(1).setIcon(tabIcons[1]);
tabLayout.getTabAt(2).setIcon(tabIcons[2]);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new PersonalDataFragment(), getString(R.string.pData));
adapter.addFragment(new AnthropometryFragment(), getString(R.string.anthro));
adapter.addFragment(new NutritionalClinicalFragment(), getString(R.string.nutcli));
viewPager.setAdapter(adapter);
}
private void registerPatient() {
try {
/*final String s_lName = i_lName.getText().toString();
final String s_fName = i_fName.getText().toString();
final String s_bday = i_bday.getText().toString();
final String s_gender = i_gender.getText().toString();
final String s_location = i_location.getText().toString();
dataBase.addPatient(s_lName, s_fName, s_bday, s_gender, s_location);*/
Toast.makeText(RegisterPatient.this, "Patient added successfully!", Toast.LENGTH_SHORT).show();
clearForm((ViewGroup) findViewById(R.id.registerlayout));
} catch (Exception e) {
Toast.makeText(RegisterPatient.this, "Something were wrong! Try it again.", Toast.LENGTH_SHORT).show();
Log.w("WARNING", e.getMessage());
Log.w("WARNING_INFO", e.getCause());
}
}
private void clearForm(ViewGroup group)
{
for (int i = 0, count = group.getChildCount(); i < count; ++i) {
View view = group.getChildAt(i);
if (view instanceof EditText) {
((EditText)view).setText("");
}
if(view instanceof ViewGroup && (((ViewGroup)view).getChildCount() > 0))
clearForm((ViewGroup)view);
}
}
#Override
public void onFragmentEditTextChanged(String lname) {
}
}
PersonalDataFragment.java
public class PersonalDataFragment extends Fragment{
public EditText editText;
public Calendar myCalendar;
public DatePickerDialog.OnDateSetListener uDate;
private getEditText listener = null;
public PersonalDataFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_pdata, null);
//Calendar
editText = (EditText) v.findViewById(R.id.input_birthday);
final EditText i_lname = (EditText) v.findViewById(R.id.input_lName);
editText.setTextIsSelectable(true);
myCalendar = Calendar.getInstance();
uDate = new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View vi) {
// TODO Auto-generated method stub
new DatePickerDialog(getActivity(), uDate, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
//Getting EditTexts
i_lname.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
#Override
public void afterTextChanged(Editable s) {
if (listener != null) {
final String stg = i_lname.getText().toString();
listener.onFragmentEditTextChanged(stg);
Toast.makeText(getActivity(), stg, Toast.LENGTH_SHORT).show();
}
}
});
return v;
}
#Override
public void onAttach(Context context) {
listener = (getEditText) context;
}
private void updateLabel() {
String myFormat = "dd/MM/yy";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
editText.setText(sdf.format(myCalendar.getTime()));
}
public interface getEditText {
public void onFragmentEditTextChanged(String lname);
}
}
I don't know what I am doing wrong. I need to get access to those EditText in order to user them and add the user to the SQLite DB but, as the EditText are in the Fragment, I cannot access them directly from the RegisterUser class.
Any ideas on how to solve this? I shall be really and deeply thankful.
Thanks in advance.
Try doing like this,
TextInputLayout FlayoutBirthday= (TextInputLayout) v.findViewById(R.id.flayout_birthday);
EditText i_lname = FlayoutBirthday.getEditText();

Categories