I have created multiple number of EditText dynamically by using loop. So I have created multiple EditText with the same name. I'am calling the DatePickerDialog when i click an EditText. I can choose the date and am setting done. Once it is completed the chosen date is only setting to the last EditText which I have created.
I want to set the date for all the EditText. Is it possible to set the value in an EditText which is created with the same name?
This is my code.
for(int i =0;i<5;i++)
{
estimate_closedate = new EditText(getActivity());
estimate_closedate.setLayoutParams(params1);
estimate_closedate.setWidth(1000);
estimate_closedate.setHint("Estimated Close Date");
estimate_closedate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DatePickerDialog dpd = new DatePickerDialog(context,
mDateSetListener, myear, mmonth, mday);
dpd.show();
}
});
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
myear = year;
mmonth = monthOfYear + 1;
mday = dayOfMonth;
if (mmonth < 10) {
month = 0 + Integer.toString(mmonth);
} else {
month = Integer.toString(mmonth);
}
if (mday < 10) {
day = 0 + Integer.toString(mday);
} else {
day = Integer.toString(mday);
}
nextdate = (new StringBuilder().append(myear).append("-")
.append(month).append("-").append(day)).toString();
estimate_closedate.setText(nextdate);
}
}
};
Try this (see my
comments
) :The point is in
setId
when you create theEditText
andfindViewbyId
to find the createdEditText
, usingfor
loop.