I'm new to Java and programming as a whole. And i've been trying to get a result set from JSON put in a Simple Adapter to load data into TextView's contained in a RelativeLayout. A link or any help in the right direction would be much appreciated, thanks in Advance. Kind Regards.
/**
* 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);
}
});
}
}
}
Here is a look at my XML File
<?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>
In a simple case like this, you can use ArrayAdapter<String>
. AdapterView
is the parent of classes like ListView
. It mainly defines View
s which children will be determined by an Adapter
; it is not the Adapter
itself.