I`m trying to delete the selected item in listView when user check its checkbox
I just cant figure out how can i get the position of the selected item when the checkbox checked. here is my custom-adapter :
public class StudentsAdapter extends BaseAdapter {
private List<Students> _studetns;
private Context _Context;
public StudentsAdapter(List<Students> _studetns, Context _Context) {
this._studetns = _studetns;
this._Context = _Context;
}
@Override
public int getCount() {
return _studetns.size();
}
@Override
public Object getItem(int position) {
return _studetns.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
class ViewHolder{
private TextView studentId;
private TextView studentName;
private TextView studentLastName;
private CheckBox checkBox;
public ViewHolder(View v)
{
studentId = (TextView) v.findViewById(R.id.lblId);
studentName= (TextView) v.findViewById(R.id.lblName);
studentLastName= (TextView) v.findViewById(R.id.lblLastName);
checkBox = (CheckBox) v.findViewById(R.id.checkBox);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Students item = _studetns.get(position);
View myLayout = View.inflate(_Context,R.layout.activity_student,null);
ViewHolder holder = new ViewHolder(myLayout);
holder.studentId.setText(String.valueOf(item.get_studentId()));
holder.studentName.setText(item.get_studentName());
holder.studentLastName.setText(item.getStudentLastName());
holder.checkBox.setTag(position);
return myLayout;
}
}
Aucun commentaire:
Enregistrer un commentaire