I have two separate class. One is my expandable recycleview and the other one is my datePickerDialog class.I have 3 textview inside my expandable child view.
I tried to return the value from the DatePickerDialog, but it said that the method is read-only, When I tried to re-assign it to another variable outside of it, and try to return the value to the adapter.. the adapter would only be able to read it after the second time i picked the date. (In this case, it showed the first date). Is there a way for me to correctly return the date value or at least wait for the value retrieved from the picker.
The textview showed it, but i wasn't able to assign it to array. Thus resulted the child view to loose it value one the parent collapse.
adapter
@Override
public void onBindChildViewHolder(final NotisChildViewHolder notisChildViewHolder, int i, Object childObject) {
final NotisChild notisChild = (NotisChild) childObject;
notisChildViewHolder.mItem.setText(notisChild.getItem());
notisChildViewHolder.mDate.setText(notisChild.getDate());
notisChildViewHolder.mTime.setText(notisChild.getTime());
// todo: take value of time & date in childview.
notisChildViewHolder.mDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Utility.onDateSelected(notisChildViewHolder.mDate, notisChild.getDate(), mContext);
Log.d(TAG, "onClick: notisChildViewHolder.mDate "+ notisChildViewHolder.mDate.getText().toString());
notisChild.setDate(notisChildViewHolder.mDate.getText().toString());
}
});
}
datePicker class
public static void onDateSelected(final TextView textView, String dateText, Context mContext) {
Log.d(TAG, "onDateSelected");
Date date = null;
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
try {
if (dateText.equals(""))
date = new Date();
else
date = simpleDateFormat.parse(dateText);
} catch (Exception exp) {
// In case of expense initializa date with new Date
date = new Date();
}
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH); // calendar month 0-11
int day = calendar.get(Calendar.DATE);
// date picker initialization
DatePickerDialog datePicker = new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
calendar.set(year, month, day);
String formattedDate = simpleDateFormat.format(calendar.getTime());
textView.setText(formattedDate);
}
}, year, month, day);
datePicker.show();
}