[英]How to pass an iterated ArrayList to another activity as a JSON Array, and make it show?
嗨,Stackoverflow社区,当我将JSON数组传递给另一个Activity时,它只是给出“ null”,您能给我一个解决方案吗?
在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);
帮助将不胜感激,谢谢您的时间!
您需要遍历数组,对于数组中的每个元素,您可以将其解析为JSON对象,然后推送到json数组。
问候,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.