1

I want to list the switch names from the database, and for that I have already implemented the application for Recyclerview list. Now, the problem is, my Recyclerview item contains the switch element, and I want to perform two functions on turning it on or off. Is that possible? I tried it on view holder on chick listener, but it gives me the same id, for every list element.



    07-07 13:25:29.915 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:30.236 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:30.439 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:30.655 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:30.860 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:31.105 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:32.210 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:32.415 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:32.599 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:32.805 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
    07-07 13:25:32.986 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1

mnille
  • 1,328
  • 4
  • 16
  • 20

1 Answers1

1

You could use OnCheckedChangeListener.

mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // do something, the isChecked will be
    // true if the switch is in the On position
}
});

See this answer

Community
  • 1
  • 1