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", ""));
}
}
});
}
}
条件を確認した後、遅れてsharedPreferenceを開始した。最初に修正してください。
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);
sharedPreferences = getSharedPreferences("prefID", Context.MODE_PRIVATE);
if(!sharedPreferences.contains("statusKey")){
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("statusKey", html);
editor.apply();
text.setText(html);
}
else {
text.setText(sharedPreferences.getString("statusKey", ""));
}
}
});
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加