Android listview with checkbox problem

前端 未结 2 1306
清歌不尽
清歌不尽 2020-12-01 00:13

I have a weird problem! I\'m trying to create a listview with checkboxes. In my other thread I was told that I should use an array that keeps track of the rows that are chec

相关标签:
2条回答
  • 2020-12-01 00:44

    This was tricky.

    The problem is that you are calling setChecked, activating the old OnCheckedChangeListener.

    The fix is quite simple: call setOnCheckedChangeListener before calling setChecked. This way you sever the link to the old listener from the recycled view.

    0 讨论(0)
  • 2020-12-01 00:59

    Check this for Single selection of Checkbox in Listview

    AdpList adapter=new AdpList(this,array,false);
    listview.setAdapter(adapter);
    

    When you select any Item then on item CLickListener do as Follows

    listview.setonItemClickListener(new OnItemClickListener)
    

    Here You will Get the Position of the Current Item

    array.get(Position);
    

    Get the Checkbox view and On clicking the Checkbox, create a method in Adapter, Like

    adapter.setList(true);
    adapter.notifyDataSetChanged();
    

    And In Adapter check the Parameter that I have Passed in the Setlist method then put condition:

    if (isChecking==true)
    {
    checkbox1.setChecked(true);
    }else{
    checkBox1.setChecked(false);
    }
    
    0 讨论(0)
提交回复
热议问题