【发布时间】:2015-04-23 21:25:12
【问题描述】:
**在进行研究并尝试查看 stackoverflow 解决方案并尝试应用它们并完全失败后,此错误仍然存在。 我正在尝试使用 SharedPreferences 和 getPreferences 来保存数据。
**如何将其用作仅包含 10 个单元格的数组?(因此它将保存我输入的最后十个值,并且我可以按最大值排序)
代码:
public void onClick(View v) {
// TODO Auto-generated method stub
SharedPreferences sharedPref = this.getPrefernces(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
EditText name = (EditText)findViewById(R.id.namep);
editor.putString(name.getText().toString(), score);
editor.commit();
}
在第一行(sharedPref 的定义)我得到了这个错误: 未为类型 new View.OnClickListener(){}
定义方法 getPrefernces(int)我试过用几种方法来切换它,但没有人能用,在此之后我什至不能调用 getActivity() 函数。我不知道为什么我的代码会扩展 Activity。 我试过这个灵魂: How to resolve an error: getSharedPreferences(String, int) is undefined for the type new View.OnClickListener(){}
The method setOnClickListener(new View.OnClickListener(){}) is undefined for the type imageButton1
【问题讨论】:
-
首选项拼写错误..
-
getPreferences 仍在工作
标签: java android sharedpreferences