0

I have listview with toggle button when i click on toggal button and scroll down then state of the button will change to Off state Please do the replay

SubbaReddy PolamReddy
  • 2,033
  • 2
  • 15
  • 23
Raja
  • 61
  • 1
  • 7

1 Answers1

0

use sharedpreference to save the state of each toggle button and load the state from the sharedpreference

Like you can define a state of your toggle (which has unique id) in sharedpreference

Here in Custom adaptor defined shared preference value.

final ToggleButton tgl=(ToggleButton)row.findViewById(R.id.tglalertstatus);

            tgl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                    if(isChecked)
                    {
                        SharedPreferences contact = context.getSharedPreferences(
                                "contact", 1);

                        editor = contact.edit();

                        editor.putInt("toggle"+tgl.getContentDescription().toString(), 1); // i set the content description for each toggle a unique string so it will work as a key for shared preference. 

                        editor.commit();
                    }
                    else
                    {
                        SharedPreferences contact = context.getSharedPreferences(
                                "contact", 1);

                        editor = contact.edit();

                        editor.putInt("toggle"+tgl.getContentDescription().toString(), 0);//i set the content description for each toggle a unique string so it will work as a key for shared preference.

                        editor.commit();
                    }

                }
            });

hope this will help.

KDeogharkar
  • 11,502
  • 7
  • 51
  • 93