0
他のアクティビティにJSON配列を渡すと、ちょうど "null"が戻されます。解決策を教えてください。反復されたArrayListを別のアクティビティにJSON配列として渡して表示させるにはどうすればいいですか?
EDITそれはonClick
最初の活動の後、停止します。
eingabe = (TextView) findViewById(R.id.tv_dish_name);
send.setOnClickListener(this);
save.setOnClickListener(this);
speicher = getApplicationContext().getSharedPreferences("jsondata", 0);
zugreifen können (hier private --> 0)
editor = speicher.edit();
}
@Override
public void onClick(View v) {
if (v == save) {
FavDishes.add(eingabe);
for (int i = 0; i < 4; i++) {
}
JSONArray jsArray = new JSONArray(FavDishes);
editor.putString("jsondata", jsArray.toString());
editor.commit();
第二の活動:
anzeige = (TextView)findViewById(R.id.anzeige);
SaveDish(anzeige.getText().toString());
speicher = getApplicationContext().getSharedPreferences("jsondata",0);
editor = speicher.edit();
private void SaveDish(String jsondata){
String strJson = speicher.getString("jsondata","0");//second parameter is necessary ie.,Value to return if this preference does not exist.
if(strJson != null) try {
JSONObject jsonData = new JSONObject(strJson);
} catch (JSONException e) {
e.printStackTrace();
}
editor.putString("jsondata",strJson);
editor.commit();
//"Data 1" als key für "Schublade Data1", value Inhalt (übergebener String)
anzeige.setText(speicher.getString("jsondata", null));
}
anzeige = (TextView)findViewById(R.id.anzeige);
ヘルプは、あなたの時間に感謝をいただければ幸いです!
こんにちはIvan、ありがとうございました! – Marius
私は簡単な例を教えてください。私はそれを正しく実装できませんでした。状況に申し訳ありません。 – Marius