【发布时间】:2020-01-22 12:19:17
【问题描述】:
当我再次打开应用程序时,我无法保存来自 textView 的数据,我在 textview 中遇到错误:
错误信息字段 XXXXX 应该是数字
我认为它没有保存任何数据,或者我使用了不正确的方法。先感谢您!
class MyJavaScriptInterface {
@JavascriptInterface
@SuppressWarnings("unused")
public void processHTML(final String html) {
myWebView.post(new Thread() {
@Override public void run() {
TextView text = findViewById(R.id.textView);
if(!sharedPreferences.contains("statusKey")){
sharedPreferences = getSharedPreferences("prefID", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("statusKey", html);
editor.apply();
text.setText(html);
}
else {
text.setText(sharedPreferences.getString("statusKey", ""));
}
}
});
}
}
【问题讨论】:
-
你能提供完整的错误堆栈吗?
-
为什么这里有javascript标签?
-
我想你的editText的inputType不是文本,尝试添加到你的editText属性android:inputType="text"
标签: java android textview sharedpreferences