所以,这是我的代码: 私有类MyBaseAdapter扩展了BaseAdapter {
LayoutInflater inflater=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@Override
public int getCount() {
// TODO Auto-generated method stub
System.out.println("I am the count method!!!!!"+startRecord+" "+endRecord);
return dataList2.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return dataList2.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
System.out.println(position+"...");
TextView textView0 = null,textView1 = null,textView2 = null,textView3 = null,textView4 = null;
CheckBox checkBox = null;
View view = null;
//ViewHolder holder = null;
if(!views.containsKey(startRecord+position)||views.get(startRecord+position)==null){
view = inflater.inflate(R.layout.workorderlistview, null);
checkBox = (CheckBox)view.findViewById(R.id.checkbox);
textView0 = (TextView)view.findViewById(R.id.errors);
textView1 = (TextView)view.findViewById(R.id.dress);
textView2 = (TextView)view.findViewById(R.id.phone);
textView3 = (TextView)view.findViewById(R.id.datestar);
textView4 = (TextView)view.findViewById(R.id.dateend);
views.put(startRecord+position, view);
textView0.setText((String)(dataList2.get(position).get("servName")));
textView1.setText((String)(dataList2.get(position).get("str1")));
textView2.setText((String)(dataList2.get(position).get("str2")));
textView3.setText((String)(dataList2.get(position).get("dispatchTime")));
textView4.setText((String)(dataList2.get(position).get("intendTime")));
final int index = position;
// checkBox.setFocusable(true);
// checkBox.requestFocus();
// checkBox.setFocusableInTouchMode(true);
// checkBox.setOnClickListener(
// new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// TODO Auto-generated method stub
// if(((CheckBox)v).isChecked()){
// System.out.println("click,toggle event.");
// ((CheckBox)v).setChecked(true);
// StringBuilder builder = new StringBuilder();
// builder.append("wassignId:");
// builder.append(dataList2.get(index).get("wassignId"));
// builder.append(",");
// builder.append("reason:");
// builder.append(dataList2.get(index).get("servName"));
// builder.append(",");
// builder.append("address:");
// builder.append(dataList2.get(index).get("str1"));
// shows.set(startRecord+index, true);
// multiList.put(startRecord+index, builder.toString());
// notifyDataSetChanged();
// }
// else{
// System.out.println("click,cancle event.");
// ((CheckBox)v).setChecked(false);
// if(multiList.containsKey(startRecord+index)) multiList.remove(startRecord+index);
// shows.set(startRecord+index, false);
// notifyDataSetChanged();
// }
// }
// }
// );
checkBox.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
System.out.println("checked method.");
StringBuilder builder = new StringBuilder();
StringBuilder builder1 = new StringBuilder();
builder.append(dataList2.get(index).get("wassignId"));
builder.append(",");
builder.append(dataList2.get(index).get("servName"));
builder.append(",");
builder.append(dataList2.get(index).get("str1"));
//shows.set(index, true);
builder1.append("'"+dataList2.get(index).get("wassignId")+"'");
shows.set(startRecord+index, true);
workidlist.put(startRecord+index, builder1.toString());
multiList.put(startRecord+index, builder.toString());
}
else{
System.out.println("uncheckde method.");
if(multiList.containsKey(startRecord+index)) multiList.remove(startRecord+index);
workidlist.remove(startRecord+index);
shows.set(startRecord+index, false);
}
}
}
);
}
else{
// holder = (ViewHolder)convertView.getTag();
view = views.get(startRecord+position);
checkBox = (CheckBox)view.findViewById(R.id.checkbox);
textView0 = (TextView)view.findViewById(R.id.errors);
textView1 = (TextView)view.findViewById(R.id.dress);
textView2 = (TextView)view.findViewById(R.id.phone);
textView3 = (TextView)view.findViewById(R.id.datestar);
textView4 = (TextView)view.findViewById(R.id.dateend);
textView0.setText((String)(dataList2.get(position).get("servName")));
textView1.setText((String)(dataList2.get(position).get("str1")));
textView2.setText((String)(dataList2.get(position).get("str2")));
textView3.setText((String)(dataList2.get(position).get("dispatchTime")));
textView4.setText((String)(dataList2.get(position).get("intendTime")));
}
if(shows.get(startRecord+position)!=null) ((CheckBox)view.findViewById(R.id.checkbox)).setChecked(shows.get(startRecord+position));
else ((CheckBox)view.findViewById(R.id.checkbox)).setChecked(false);
return view;
}
}
这意味着我使用show(map)来保持每个复选框的状态,因为当我回到这个时我使用意图到另一个活动时,我希望每个复选框保持它的状态。(我是中国人,我的英语不是很好:)抱歉。),问题是,在第一页,我可以点击复选框,没关系。但是,当我转到第二页时,如果我不将列表视图滑动到最后一项,我无法点击复选框。