how to get array size only when check box is checked

78 views Asked by At

hi i m new to android i m working on expandable list and i have a sub list of checkbox, so i need to display only checked items size how can i do this ,,,, thanks in advance

expListView.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                // TODO Auto-generated method stub
                  CheckBox cb = (CheckBox)v.findViewById( R.id.check1 );
                    cb.getText().toString();
                    System.out.println("......"+cb);

                    if( cb != null )
                        cb.toggle();
                Toast.makeText(
                        getApplicationContext(),
listDataHeader.get(groupPosition)+ " : "+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition), Toast.LENGTH_SHORT).show();
selected=listDataHeader.get(groupPosition)+ " : "+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition);
                System.out.println("value of" + selected);
                String a1=listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition);
                limits.add(selected);
                //String a= selected.toString();
                int si= limits.size();
                tv1.setText(a1);
                tv2.setText(""+si);
                System.out.println("length..."+si);
                return false;
            }
        });
1

There are 1 answers

1
Dilavar Malek On

implement this interface in your class OnCheckedChangeListener

    class Abc implements OnCheckedChangeListener {

expListView.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                // TODO Auto-generated method stub
                  CheckBox cb = (CheckBox)v.findViewById( R.id.check1 );
                    cb.getText().toString();
                    System.out.println("......"+cb);

                    if( cb != null )
                        cb.toggle();
                Toast.makeText(
                        getApplicationContext(),
listDataHeader.get(groupPosition)+ " : "+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition), Toast.LENGTH_SHORT).show();
selected=listDataHeader.get(groupPosition)+ " : "+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition);
                System.out.println("value of" + selected);
                String a1=listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition);
                limits.add(selected);
                //String a= selected.toString();
                int si= limits.size();
                tv1.setText(a1);
                tv2.setText(""+si);
                System.out.println("length..."+si);
                return false;
            }
        });
    @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
               your code here

        }
    }