private Button deleteSel;
c.moveToFirst();
while(!c.isAfterLast())
{
tskId[i] = c.getInt(0);
tskType[i] = c.getString(1);
tskDate[i] = c.getString(2);
taskStatus[i] = (c.getString(3).equals("true"))? true : false;
alarmStatus[i] = (c.getString(4).equals("true"))? true : false;
i++;
c.moveToNext();
}
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
//aList = new ArrayList<HashMap<String,String>>();
for(i=0;i<c.getCount();i++){
hm = new HashMap<String,String>();
hm.put("txtTitle", tskType[i]);
hm.put("txtTime",tskDate[i]);
aList.add(hm);
}
c.close();
CustomListAdapter listAdapter = new CustomListAdapter(this , R.layout.deletes_supporting , aList);
lstvwDelete.setAdapter(listAdapter);
}
// customListAdapter是用户定义的类来设计listview 现在我想删除用户使用deleteButton检查的项目。请帮助...
答案 0 :(得分:0)
执行此操作的一种方法是将复选框绑定到任务ID。在CustomListAdapter中,您可以将复选框的ID设置为任务ID。
checkBoxViewHolder.setId(listItems.get(position).getId());
现在你可以在活动中做这样的事情了。
deleteButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//int i = 0;
for(int i = 0;i < tasks.size(); i++) {
int taskId = tasks.get(i).getId();
CheckBox cb = (CheckBox)taskListView.getChildAt(i).findViewById(taskId);
if(cb.isChecked()) {
dbAdapter.deleteTask(taskId);
}
}
}
});