0
我在Android和面临的问题,在这里共享偏好 新的保存在列表视图切换按钮的状态是什么,我试图做如何使用共享偏好
- 我的应用程序中包含微调和列表视图
- 的列表视图过得去微调,我成功打造
- 列表视图中的每一行中含有关于选择
保存切换按钮的状态,我现在使用的共享偏好在这里,我对名单中被卡住
final ToggleButton btnlock = (ToggleButton) view.findViewById(R.id.btn);
btnlock.setTag(pIndex);
btnlock.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(btnlock.isChecked()){
btnlock.setButtonDrawable(a_icon);
btnlock.setChecked(true);
position = (Integer) buttonView.getTag();
sp = getPreferences(MODE_PRIVATE);
Editor editor = getSharedPreferences("MyPref", 0).edit();
editor.putBoolean("in"+month+"_"+position, true);
editor.commit();
}else{
btnlock.setButtonDrawable(a_dicon);
btnlock.setChecked(false);
sp = getPreferences(MODE_PRIVATE);
Editor editor = getSharedPreferences("MyPref", 0).edit();
editor.putBoolean("in"+month+"_"+position, false); editor.commit();
}
}
});
我用这
public View getView(final int index, View view, final ViewGroup parent) {
sp = getSharedPreferences("MY_Pref", 0);
btnlock.setChecked(sp.getBoolean("in"+month+"_"+position,false));
Toast.makeText(getApplicationContext(), "chking"+month+"_"+position+"_"+sp.getBoolean("on"+position ,false),
Toast.LENGTH_LONG).show();
}
这个土司味精是显示我总是假的,位置始终是一个常数 为什么我得到这个以及如何解决这个问题?
什么是“SP”?评论太短 –
sp是分享prefernces名称 – user2750762
看到答案,你的问题是不同的文件名 –