0

I am using the following: - I have a DialogFragment, the view contains a listview and a button - the listview contains an imageview, a textview, and a checkbox - I have a Custom adapter for the listview

What is need is the values of the checkboxes after I press the button in my DialogFragment view. How do I do that? How can I access the values of the checboxes, which are only known inside my adapter (as far as I know) from outside my adapter?

Can I add a public method in my adapter, where the values of the checboxes are stored? Or is there another way?

deimos1988
  • 5,896
  • 7
  • 41
  • 57

1 Answers1

0

Ok, so what you can do ... in your adapter class create instance variable

SparseBooleanArray mCheckStates;

then initialize it in constructor, where data.length is length of values that you want to display

mCheckStates = new SparseBooleanArray(data.length);

then you can implemented methods in your adapter like :

public boolean isChecked(int position) {
    return mCheckStates.get(position, false);
}

public void setChecked(int position, boolean isChecked) {
    mCheckStates.put(position, isChecked);

}

public void toggle(int position) {
    setChecked(position, !isChecked(position));

}

and you are good to go ... for more info you can see this link: Get Selected Item Using Checkbox in Listview

Community
  • 1
  • 1
Matej Špilár
  • 2,617
  • 3
  • 15
  • 28