I'm new in android development. I have created a expandable listview which have checkboxes.I'm finding diffculty in iterating through the checkboxes and getting the text of the checkboxes that user have selected.I've used a array string to store the checked value of checkbox but this method doesn't seem to work.The toast displays the text of some other checkbox rather than the selected.
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final String childText =(String) getChild(groupPosition,childPosition);
if(convertView == null){
LayoutInflater layoutInflater=(LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=layoutInflater.inflate(R.layout.expand,null);
}
cBox=convertView.findViewById(R.id.chkbx);
cBox.setText(childText);
cValues=new ArrayList<>();
for(int i=0;i<_listDataChild.size();i++) {
cBox.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (cBox.isChecked()) {
Toast.makeText(context, "" + cBox.getText().toString(), Toast.LENGTH_SHORT).show();
cValues.add(cBox.getText().toString());
}
}
}
);
}
return convertView;
}
}
Aucun commentaire:
Enregistrer un commentaire