我有一个显示一些项目和按钮的应用程序。用户可以隐藏任何这些按钮或项目。在设置中,用户可以删除按钮1:
case R.id.action_delete:
button1.setVisibility(View.GONE);
return false;
它工作正常,但问题是当用户重新启动应用程序时,按钮1将再次出现。
答案 0 :(得分:1)
public static final String PREFS_NAME = "Prefs";
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings.getString("button", "").toString().equals("button")) {
button1.setVisibility(View.GONE);
}
}
case R.id.action_delete:
button1.setVisibility(View.GONE);
SharedPreferences preferences = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("button", "button");
editor.commit();
return false;