你能告诉我如何在android中列出动态数据列表中的响应数据吗?。我能从服务器获取数据,然后从响应中创建一个数组。现在我想要 在列表视图上显示。我创建了一个xml,我在其中编写文本视图。然后我需要做什么?
<?xml version="1.0" encoding="utf-8"?>
<!-- Single List Item Design -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
package com.example.twat;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class MainActivity extends Activity {
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new AsyncTask<Void, Void, String>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
showProgressDialog("Please Wait...");
}
@Override
protected String doInBackground(Void... params) {
WebServiceRequestManager manager = new WebServiceRequestManager();
return manager.getMethod("httpa/destinationdashboard?crsCode=add");
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
System.out.println("Respose : " + result);
hideProgressDialog();
try {
JSONObject js =new JSONObject(result);
String stationName[] = null;
JSONArray arr=js.getJSONArray("data");
for (int i = 0; i < arr.length(); i++) {
stationName[i] = arr.getJSONObject(0).get("tocName").toString();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.execute();
}
public void showProgressDialog(final String msg) {
runOnUiThread(new Runnable() {
public void run() {
if (progress == null || !progress.isShowing()) {
progress = ProgressDialog.show(MainActivity.this, "", msg);
progress.setCancelable(false);
}
}
});
}
public void hideProgressDialog() {
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (progress.isShowing())
progress.dismiss();
} catch (Throwable e) {
}
}
});
}
}