我创建了一个动态表格。表单中的字段是根据后端中设置的字段类型创建的。动态创建的editText的所有数据都在arrayList中设置。类型“ String”没有问题,但是如果是日期,则会出现问题。问题是,如果有2个日期字段,即使我选择并设置第一个日期字段的日期字段,也会设置最后一个日期字段的值。该代码可以在下面看到:
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;
}