-1
我想添加一些json項目到我的列表視圖。我怎樣才能在java文件中添加項目?Android將項目添加到列表
JSON例如:
{"responseData": {"media":[{
"freshness":"1",
"critic":"Roger Moore",
"quote":"Adequate",
"publication":"McClatchy-Tribune News Service",
"date":"2013-01-08"
},
{
"freshness":"1",
"critic":"Laremy Legel",
"quote":"You won't be upset you saw it, you'll have some fun, you'll see Wolvie beat the living hell out of a helicopter.",
"publication":"Film.com","date":"2010-07-07"
},
{
"freshness":"1",
"critic":"Sara Vilkomerson",
"quote":"Did the plot points stick in my head five minutes after leaving the theater? Not so much ... but I know I was having fun while watching.",
"publication":"New York Observer",
"date":"2009-05-06"
}
}]}}
的java
String url = "http://site.com/";
aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject json, AjaxStatus status) {
if(json != null){
JSONArray ja = json.optJSONObject("responseData").optJSONArray("media");
try {
String test = null;
for(int i = 0 ; i < ja.length(); i++){
JSONObject jo = ja.optJSONObject(i);
test = jo.getString("critic");
Toast.makeText(aq.getContext(), test, Toast.LENGTH_LONG).show();
//add items to list//
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//end try
}//end if null
}//end callback
});
list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#FF800000"
>
</ListView>
list_body.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/freshness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/critic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"/>
</LinearLayout>
我想添加一些json項目到我的列表視圖。我怎樣才能在java文件中添加項目?