I am trying to delete an item from an arraylist called arrayofTask by having checked a checkbox. I have tried many ways to accomplish this, but have been unsuccessful.
Visit https://imgur.com/gallery/oRdhpGR which is where i uploaded a picture of my listview which i add a task and description with an add button.
what i am trying to do is delete such task and description with the click of the checkbox
bellow is what i have been trying to do but i dont know how to proceed.
listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, final int position, long id) {
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkBox.isChecked()){
arrayOfTask.remove(position);
adapter.notifyDataSetChanged();
}
}
});
}
this is my custom adapter
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;
}
Aucun commentaire:
Enregistrer un commentaire