我是 Java 和整个编程的新手。我一直在尝试从 JSON 中获取一个结果集,并将其放入一个简单的适配器中,以将数据加载到包含在 RelativeLayout 中的 TextView 中。非常感谢您提供正确方向的链接或任何帮助,在此先感谢。亲切的问候。
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into RelativeLayout
* */
AdapterView adapter = new AdapterView(
AllProductsActivity.this, productsview,
R.layout.sample_view, new String[] { TAG_PID,
TAG_NAME},
new int[] { R.id.pid, R.id.name });
// updating View view
setAdapter(adapter);
}
});
}
}
}
这是我的 XML 文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sample_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/pid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/name"
android:layout_below="@+id/name"
android:layout_marginTop="88dp"
android:text="Product ID"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="35dp"
android:layout_marginTop="24dp"
android:text="Product Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>