Jsonからデータを取ってきてリストに入れるプログラムを書いているのですが、そのJsonをリストビューの部品に入れて表示する方法がわかりません。
Java
1 final ArrayList<String> list = new ArrayList<>(); 2 JSONArray eventArray = result.getJSONArray("bookin"); 3 for (int i = 0; i < eventArray.length(); i++) { 4 JSONObject eventObj = eventArray.getJSONObject(i); 5 6 //JSONObject event = eventObj.getJSONObject("event"); 7 //Log.d("title", event.getString("title")); 8 list.add(eventObj.getString("title")); 9 list.add(eventObj.getString("name")); 10 11 } 12 13 // ListView 用のアダプタを作成 14 final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>( 15 ReturnSelect.this , 16 android.R.layout.simple_list_item_1, 17 list 18 ); 19 20 listView.setAdapter(arrayAdapter); 21
Json
1{"bookin":[{"title":"\u3084\u3055\u3057\u3044JavaScript\u306e\u304d\u307b\u3093","name":"\u5ddd\u6751\u96c5\u4e4b"},{"title":"\u3084\u3055\u3057\u3044JavaScript\u306e\u304d\u307b\u3093","name":"\u5ddd\u6751\u96c5\u4e4b"}]}
XML
1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <LinearLayout 7 android:orientation="vertical" 8 android:layout_width="match_parent" 9 android:layout_height="match_parent" 10 android:layout_weight="1" 11 > 12 13 <TextView 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:id="@+id/title" 17 android:layout_below="@+id/list_with_button_text" 18 android:textSize="30dp" /> 19 20 <TextView 21 android:layout_width="wrap_content" 22 android:layout_height="wrap_content" 23 android:id="@+id/name" 24 android:layout_below="@+id/list_with_button_text2" 25 android:textSize="30dp" /> 26 </LinearLayout> 27 28</LinearLayout>
実際にはこういうコードで書いているのですができません。ぜひ、知恵をお貸しください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/09 12:08
2016/07/09 14:38