mercredi 23 août 2017

android listview checkbox event

i'm trying to implement custom listview. however, i can't get the click event for my checkbox;

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    final int pos = position;
    View view = convertView;

    if(view == null){
        LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listview,parent, false);
    }
    TextView textview = (TextView)view.findViewById(R.id.listview_text);
    final CheckBox checkbox = (CheckBox)view.findViewById(R.id.listview_check);
    checkbox.setFocusable(false);
    checkbox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(context, pos+"", Toast.LENGTH_SHORT).show();
        }
    });

    return super.getView(position, convertView, parent);
}

I want that if I clicked checkbox in ListView, pop the Toast about row position. But, this code run just check box click event just 0 row. checkbox in other row don't trigger event.

how can i fix it?




Aucun commentaire:

Enregistrer un commentaire