2017-07-08 7 views
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); 

ヘルプは、あなたの時間に感謝をいただければ幸いです!

答えて

0

あなたは配列を繰り返し処理する必要があります。配列ごとにJSONオブジェクトを解析してjson配列にプッシュできます。

よろしくお願いします。

+0

こんにちはIvan、ありがとうございました! – Marius

+0

私は簡単な例を教えてください。私はそれを正しく実装できませんでした。状況に申し訳ありません。 – Marius

関連する問題