【发布时间】:2019-07-02 00:22:37
【问题描述】:
我正在尝试从名为 arrayofTask 的数组列表中删除一个项目 通过选中一个复选框。我尝试了很多方法来实现这一点,但都没有成功。
访问https://imgur.com/gallery/oRdhpGR,在那里我上传了我的列表视图的图片,我使用添加按钮添加了任务和描述。
我要做的是通过单击复选框删除此类任务和描述
下面是我一直在尝试做的,但我不知道如何进行。
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkBox.isChecked()){
///i want to delete the arrayoftasks thats located in this location.
///tho i am unable to get the location for the tasks in this location.
///so if i check the box it should delete the items
}
}
});
这是我的自定义适配器
public class userAdapter extends ArrayAdapter<user> {
public userAdapter(Context context, ArrayList<user> users){
super(context,0,users);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
final user User = getItem(position);
CheckBox checkbox;
if(convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item,parent,false);
}
///this new
checkbox = (CheckBox) convertView.findViewById(R.id.checkbox);
///above
TextView tvTask = (TextView) convertView.findViewById(R.id.task);
TextView tvDescription = (TextView) convertView.findViewById(R.id.description);
tvTask.setText(User.task);
tvDescription.setText(User.description);
return convertView;
}
【问题讨论】:
标签: java android android-studio checkbox