一旦我关闭模拟器然后再次运行它,我就无法保存按钮的状态。这是 onCreate 和 onDestory 中的代码
@Override
protected void onDestroy() {
super.onDestroy();
ViewGroup v=(ViewGroup) findViewById(R.id.GridLayout1);
SharedPreferences setting= getSharedPreferences("MyPrefs",0);
SharedPreferences.Editor editor=setting.edit();
for(int i=2; i < ((ViewGroup)v).getChildCount(); i++) {
View childView = ((ViewGroup)v).getChildAt(i);
int resID = childView.getId();
Button btn = (Button) findViewById(resID);
editor.putString("value",btn.getText().toString());
editor.commit();
}
}