Select All items of a ListView (custom row with checkbox in it)

后端 未结 3 1873
生来不讨喜
生来不讨喜 2021-02-13 09:59

What I have: I have a ListView with custom rows, having a CheckBox & two TextViews in each row. I have a button for \"Select All\".

What i

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 10:22

    I think you should run this long-running task off the UI thread. When you click button in OnClickListener:

    new Thread(new Runnable() {
                            @Override
                            public void run() {
                                for (int i = 0; i < list.getAdapter().getCount(); i++) {
                                    final int position = i;
                                    mHandler.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            list.setItemChecked(pos, true);  
                                        }
                                    });
                                }
                            }
                        }).start();     
    

    and in onCreate() :

    this.mHandler = new Handler();
    

    Each item in list view should be Checkable like CheckableRelativeLayout that implements Checkable interface.

提交回复
热议问题