我有一个ExpandableListAdapter,我正在使用像这样的持有者填充孩子
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
View v = convertView;
ChildElement e= new ChildElement();
e.childPosition = childPosition;
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.main_list_item, null);
holder = new ViewHolder();
holder.itemname = (TextView) convertView.findViewById(R.id.image_icon);
holder.Save_check = (CheckBox) convertView.findViewById(R.id.checkBox);
////holder.Save_check.setTag(childPosition);
holder.Remarks = (EditText) convertView.findViewById(R.id.remarks);
holder.Qty = (EditText) convertView.findViewById(R.id.qty);
holder.Date = (EditText) convertView.findViewById(R.id.date);
////holder.Date.setTag(childPosition);
holder.Time = (EditText) convertView.findViewById(R.id.time);
////holder.Time.setTag(childPosition);
holder.itemname = (TextView) convertView.findViewById(R.id.image_icon);
holder.Date.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int getDPPostion = (Integer) holder.Date.getTag();
String DP = getChild(groupPosition, childPosition).toString();
long SP = getChildId(groupPosition, childPosition);
GP = groupPosition; CP = childPosition;
showDialog(DATE_DIALOG_ID);
globalPosition = holder.ref;
}
});
////convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.itemname.setText(getChild(groupPosition, childPosition).toString().toLowerCase());
return convertView;
}
并且在适配器外面我就像这样的日期列表器
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;
///final Calendar c = Calendar.getInstance();
//final ViewHolder holder;
//int getPostion = (Integer) view.getTag();
String date = (month + 1)+"/"+year;
holder = new ViewHolder();
holder.Date.setText(date);
};
和一个对话框
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
// set date picker as current date
return new DatePickerDialog(MenuScreen.this, datePickerListener, year, month,
day);
case TIME_DIALOG_ID:
// set time picker as current time
return new TimePickerDialog(MenuScreen.this, timePickerListener, hour, minute,
false);
}
return null;
}
但它给出了空指针异常。