【发布时间】:2014-08-17 11:25:22
【问题描述】:
我正在开发一个获取 API 客户端列表的应用程序,我需要在列表视图中显示它,我正在使用 volley,我尝试做的是以下操作,但它不起作用:
public ListView txtDisplay;
@Override
protected Boolean doInBackground(Void... params) {
try {
txtDisplay = (Listview) findViewById(R.id.listView);
String url = "http://192.168.1.1/rep-mais-api/api";
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
findViewById(R.id.progressBar1).setVisibility(View.GONE);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("Error: " + error.getMessage());
}
})
ActivityMain.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager" />
<TextView
android:id="@+id/txtDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"/>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
【问题讨论】:
标签: android listview android-listview android-volley