我已经实现了带有复选框和文本视图的自定义列表视图。当列表视图不在滚动时它工作正常,但是如果行增加,那么当我单击复选框时,列表视图处于滚动视图中,选中标记不会保留。这是我的代码,如果该代码有任何问题,请建议我
public class ArchivedAdapter extends ArrayAdapter<MessageBean> {
final ArrayList<MessageBean> updatedList = new ArrayList<MessageBean>();
private List<MessageBean> list;
private TextView officenameView, sentOnView, messageView;
public final static String MY_ACTION = "com.android.threeptalk.broadcast";
private boolean isDeleted = false;
int count = 0;
HashMap<Integer, CheckBox> checkList = new HashMap<Integer, CheckBox>();
public ArchivedAdapter(Context context, int resourseID,
List<MessageBean> list) {
super(context, resourseID, list);
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public MessageBean getItem(int arg0) {
return list.get(arg0);
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
LayoutInflater inflater = (LayoutInflater) this.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.archievedmsgrow, parent, false);
row.setId(position);
Object obj = getItem(position);
if (obj instanceof MessageBean) {
final MessageBean message = (MessageBean) obj;
CheckBox checkBox = (CheckBox) row.findViewById(R.id.checkBox);
officenameView = (TextView) row.findViewById(R.id.officename);
sentOnView = (TextView) row.findViewById(R.id.time);
messageView = (TextView) row.findViewById(R.id.message);
officenameView.setText(message.getOfficeName());
checkList.put(position, checkBox);
checkBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
CheckBox c = (CheckBox) v;
if (c.isChecked()) {
c.setChecked(true);
count++;
updatedList.add(message);
} else {
c.setChecked(false);
count--;
updatedList.remove(message);
updatedList.size());
}
checkedCount(count, updatedList);
}
});
row.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rowclicked(message, position);
}
});
sentOnView.setText(Common.getAppropriateTimeUsingTimeZone(message
.getmDate()));
if (message.getMessage() != null) {
messageView.setText((message.getMessage()));
} else {
if (message.getMessageType().equals("OPTION")) {
if (message.getOptions() != null
&& message.getOptions().size() > 0) {
String data = message.getOptions().get(0);
if (data != null && !data.equals("")) {
messageView.setText(data);
}
}
}
}
}
return row;
}
protected void messageSelected() {
}
protected void rowclicked(MessageBean message, int position) {
// TODO Auto-generated method stub
}
protected void checkedCount(int count2, ArrayList<MessageBean> updatedList) {
}
}
`