Answers to Implement Section ListView with Checkbox? ( 1 )

  1. 2017-01-02 10:01

    You can implement a Custom interface in your Adapter. When you checked your item from list you have to pass the result to your Activity and later you can make sum of it.

    interface CheckItemList{
    
            public void onCheckItem(int value){}
    
        }
    

    In your Adapter Class create a reference of Interface and call onCheckItem()

    CheckItemList checkItemList = (CheckItemList) mContext;
    
    satView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    
           @Override
           public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
                  if(isChecked){
           checkItemList.onCheckItem(value);
             }
           }
       }
    ); 
    

    Implement CheckItemList interface in your activity or some singleton class.

    class MyActivity extends Activity implements CheckItemList.
      onCheckItem(int value){
      //Add your code to store checked value  
    }
    

    }

Leave a reply to - Implement Section ListView with Checkbox?

◀ Go back