我有一个包含edittext和复选框的listView,我的问题是edittext返回列表中的最后一项null,我想保留最后一项的可编辑文本并返回它,请帮助
这是我的getView代码
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
View itemView = convertView;
if (itemView == null){
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
itemView = inflater.inflate(R.layout.item, null);
holder = new ViewHolder();
holder.textView1 = (TextView) itemView.findViewById(R.id.textView1);
holder.check1 = (CheckBox) itemView.findViewById(R.id.check1);
holder.check2 = (CheckBox) itemView.findViewById(R.id.check2);
holder.note = (EditText) itemView.findViewById(R.id.note);
itemView.setTag(holder);
}
else{
holder = (ViewHolder) itemView.getTag();
}
holder.check1.setTag(position);
holder.check2.setTag(position);
final Item item = items.get(position);
holder.note.setText(items.get(position).notes);
holder.note.setId(position);
holder.note.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus){
final int position = v.getId();
final EditText Caption = (EditText) v;
items.get(position).notes = Caption.getText().toString();
}
}
});
holder.textView1.setText(item.getName());
holder.check1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(buttonView.isPressed()){
if (position != ListView.INVALID_POSITION) {
Item p = items.get(position);
p.setSelectedcheck1(isChecked);
item.setFound(true);
}
}
}
});
holder.check2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(buttonView.isPressed()){
if (position != ListView.INVALID_POSITION) {
Item p = items.get(position);
p.setSelectedcheck2(isChecked);
item.setWorking(true);
}
}
}
});
holder.check1.setChecked(item.isSelectedcheck1());
holder.check2.setChecked(item.isSelectedcheck2());
return itemView;
}
}
class ViewHolder {
public TextView textView1;
public CheckBox check2,check1;
EditText note;
}
}