我有一个包含 ImgaeView 的 ListItem。每当单击其图像或图标时,我都想删除 ListItem。这是我的 ListItemActivity。如何调用适配器的 remove 方法来删除 ListItem?我在引用时遇到问题。请让我知道是否有更好的方法。
public class TaskListItem extends LinearLayout {
private Task task;
private TextView taskName;
private TextView responsible;
private TextView priority;
private ImageView bin;
protected TaskListAdapter adapter;
public TaskListItem(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
taskName = (TextView)findViewById(R.id.task_name);
responsible = (TextView)findViewById(R.id.responsible);
priority = (TextView)findViewById(R.id.priority);
bin = (ImageView)findViewById(R.id.remove_task);
}
public void setTask( final Task task) {
this.task = task;
taskName.setText(task.getName() + " ");
//Set responsibility text
responsible.setText("Resp: " + task.getReponsible());
//Set priority text
priority.setText(" Prio: " + task.getPiotiry());
/*
* onClickListener for image to delete
*/
bin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
**call the adapters remove method to delete this item with parameter (this).**
}
});
}
public Task getTask() {
return task;
}
}