如何在选中复选框时获取数组大小

时间:2014-11-22 04:49:40

标签: android checkbox expandable

嗨,我刚接触到android我正在开发可扩展列表,我有一个复选框的子列表,所以我需要只显示选中的项目大小我该怎么做,,,,提前谢谢

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 个答案:

答案 0 :(得分:0)

在您的类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

        }
    }