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
            Asked
            
        
        
            Active
            
        
            Viewed 913 times
        
    0
            
            
        - 
                    Where is the toggle button? – salezica Mar 02 '13 at 06:59
 
1 Answers
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
        
- 10,939
 - 7
 - 51
 - 95