嗨,我是安卓新手,我正在处理可扩展列表,我有一个复选框的子列表,所以我需要只显示选中的项目大小我该怎么做 ,,,,提前感谢
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;
}
});
在你的
类中实现这个接口 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
}
}