2013-03-02 56 views
0

我有一个切换按钮列表视图当我toggal点击链接,然后向下滚动,则该按钮的状态更改为关闭状态 请不要重播国家不切换按钮更改

+0

切换按钮在哪里? – slezica 2013-03-02 06:59:13

回答

0

使用sharedpreference保存的状态每一个切换按钮,并从sharedpreference

加载状态就像你可以在自定义接口共享偏好值sharedpreference

定义切换的状态(有唯一的ID)在这里。

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(); 
        } 

       } 
      }); 

希望这会有所帮助。