Get Value From Checkbox In Custom Listview
Well I have implemendes a HashMap where the key is a String and the value is a Integer the thing is that I'd like to know how could I get the value of the radio button clicked, to
Solution 1:
Press "Accept" I can get the sum of all of the CheckBox of the ListView
Create a method inside HashMapArrayAdapter
which return checked entry value and call it on Accept
Button click:
1. Declare a HashMap with position as key and entry.getValue()
as key for storing checked CheckBox values:
Map<Integer, String> checkedCheckBoxValues = new HashMap<Integer, String>();
2. Now create a method which return HashMap<Integer, String>
in HashMapArrayAdapter
class :
publicHashMap<Integer, String> getCheckedCheckBoxs(){
return checkedCheckBoxValues;
}
3. Add key and value inside onCheckedChanged
to checkedCheckBoxValues
:
checkedCheckBoxValues.put(position,String.valueOf(entry.getValue()));
4. Call getCheckedCheckBoxs
method on Accept
Button click using adapter
:
@OverridepublicvoidonClick(View v) {
mDialog.dismiss();
HashMap<Integer, String> checkedValues=adapter.getCheckedCheckBoxs();
}
Post a Comment for "Get Value From Checkbox In Custom Listview"