我有一个带有 3 个 EditText 的列表视图。一个 EditText 是一个日期字段,我在该字段上放置了一个 onClickListener 以打开 datePickerDialog。我的问题是当我选择一个日期时,它不会将文本放回 EditText 中。有谁知道如何解决这一问题?
这是我的代码:
public class BezoekverslagAfsprakenListAdapter extends ArrayAdapter<Afspraak> implements OnDateSetListener{
public Context context;
public List<Afspraak> afspraken;
ViewHolder holder;
DatePickerDialog dialog;
int dag, maand, jaar;
DatePicker picker;
public BezoekverslagAfsprakenListAdapter(Activity context, List<Afspraak> afspraken){
super(context, R.layout.afspraak_item, afspraken);
this.context = context;
this.afspraken = afspraken;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.afspraak_item, null, false);
holder = new ViewHolder();
holder.afspraak = (EditText)convertView.findViewById(R.id.et_afspraak);
holder.wie = (EditText)convertView.findViewById(R.id.et_wie);
holder.datum = (EditText)convertView.findViewById(R.id.et_datumAfspraak);
holder.position = position;
convertView.setTag(holder);
holder.datum.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
// your click actions go here
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
dialog = new DatePickerDialog(context, position, null, mYear, mMonth, mDay);
dialog.show();
}
});
}
else{
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
static class ViewHolder {
EditText afspraak;
EditText wie;
EditText datum;
int position;
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
monthOfYear = monthOfYear +1;
holder.datum.setText(dayOfMonth+"-"+monthOfYear+"-"+year);
}
}