0
我正在實現Android中默認消息應用程序等通知的功能。現在我通過添加複選框來刪除多個消息,在複選框中我使用一個常用複選框來選擇列表中的所有消息。但我無法檢查CustomAdpter的getview中的listview複選框。選擇全部並清除所有選擇複選框
class customListAdpter extends BaseAdapter {
private Context ctx;
CheckBox checkBox;
TextView sender, message;
customListAdpter(Context context) {
this.ctx = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return new NotifiCation().senderlist.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int pos, View v, ViewGroup arg2) {
// TODO Auto-generated method stub
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.checkboxlist, null);
checkBox = (CheckBox) v.findViewById(R.id.btn_chck);
sender = (TextView) v.findViewById(R.id.text_senderno);
message = (TextView) v.findViewById(R.id.text_msg);
}
sender.setText("" + new NotifiCation().senderlist.toArray()[pos]);
message.setText("" + new NotifiCation().msglist.toArray()[pos]);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (buttonView.isChecked()) {
}
}
});
return v;
}
}
這是我的主要活動。在這裏我有主複選框。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.delete_notifications);
db = new DB(NotificationsDelete.this);
notifications = (ListView) findViewById(R.id.list_with_ckbox);
selectAll = (CheckBox) findViewById(R.id.btn_checkall);
done = (Button) findViewById(R.id.done_notification_delete);
notifications.setAdapter(new customListAdpter(con));
selectAll.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton chkbox, boolean arg1) {
if (chkbox.isChecked() == true) {
for (int i = 0; i < new NotifiCation().senderlist.size(); i++) {
//notifications.setItemChecked(i, true);
customListAdpter adpter=new customListAdpter(con);
adpter.checkBox.setChecked(true);
}
} else {
// new customListAdpter(con).checkBox.setChecked(true);
}
}
});
done.setOnClickListener(this);
}