I have created a dynamic form. The field in the form is created in respect to the field type set in the backend. All the data of the dynamically created editText is set in arrayList. There is no problem for type "String" but in case of date, a problem occurs. The problem is that if there are 2 date fields, the value of the last datefield is set even if i chose and set the date field of first date field. The code can be seen below:
call.enqueue(new Callback<SifarisMainModel>() {
@Override
public void onResponse(Call<SifarisMainModel> call, retrofit2.Response<SifarisMainModel> response) {
String url = call.request().toString();
Log.e("urlChoseSifaris",url.toString() + "");
for(FieldArray fieldArray: response.body().getFiledArray()){
counter++;
name = fieldArray.getNepaliName();
fieldType = fieldArray.getFieldType();
keyList.add(fieldArray.getName());
getForm();
}
}
@Override
public void onFailure(Call<SifarisMainModel> call, Throwable t) {
}
});
public void getForm(){
case "DATE":
et = new EditText(this);
list.add(et);
et.setInputType(InputType.TYPE_CLASS_DATETIME);
et.setTextColor(getResources().getColor(R.color.black));
sifarisMainlayout.addView(et);
et.setFocusable(false);
et.setCursorVisible(false);
et.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(ChooseSifaris.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(android.widget.DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
et.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
});
break;
}