JSON Array to Listview
I'm creating an application which receives tuples from a MySQL database and converts this into a JSON array. This is currently working. Below is the JSON array;
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","payslip_id: "+json_data.getInt("payslip_id")+
", user_id: "+json_data.getString("user_id")+
", date: "+json_data.getString("date")+
开发者_StackOverflow社区 ", units: "+json_data.getInt("units")+
", rate: "+json_data.getInt("rate")+
", grosspay: "+json_data.getInt("grosspay")+
", deductions: "+json_data.getInt("deductions")+
", netpay: "+json_data.getInt("netpay"));
returnString += "\n\t" + jArray.getJSONObject(i);
This is currently shown in a textview producing the below output (there will be more records this is just for example)
[{"payslip_id":"1","user_id":"2","date":"04-04-2011","units":"18","rate":"7","grosspay":"400","deductions":"100","netpay":"300"}]
My question is how can I output this in a listview to display up to 12 records? Any help with this is greatly appreciated. Thanks for your time guys. I'm doing my best to understand but I'm fairly new to this concept.
Use the for cycle to add the items to an ArrayList. Then use an ArrayAdapter.
Updated - better example: http://www.lacherstorfer.at/haris_blog/2008/03/android-howto-create-spinners.html
精彩评论