Possible Duplicate:
Adapter for a custom layout of listview
ArrayAdapter<String> adapter = null;
JSONArray productsList = null;
try {
productsList = obj5.getJSONArray("Content");
} catch (JSONException e2) {
e2.printStackTrace();
}
if(productsList != null){
ListView lv = (ListView) findViewById(android.R.id.list);
for (int i=0; i<productsList.length(); i++) {
final String[] items = new String[productsList.length()];
String product = null;
try {
product = productsList.getJSONObject(i).getString("Quantity")+" X "+
productsList.getJSONObject(i).getString("Name") +" "+
Currency.britishPound+productsList.getJSONObject(i).getString("MinCost");
} catch (JSONException e) {
e.printStackTrace();
}
if(product!=null){
items[i]=product;
}
adapter = new ArrayAdapter<String>(APIQuickCheckout.this, R.layout.product_item, R.id.label, items);
lv.setAdapter(adapter);
}
Here is my list view:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dip"
android:layout_weight="30">
</ListView>
And here is how I pass each product seperately.
<?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="16sp"
android:textStyle="bold" >
</TextView>
Now and according to the the aforementioned code I’m passing to each line just a simple string. However, I was wondering how could I pass three different Strings. The reason that I want to pass three different Strings is that I want them to be in the following format:
Quantity X
Number Price(this should be at the end of the line)
You have to derive from adapter, and provide properly filled views. Like here:
https://github.com/ko5tik/camerawatch/blob/master/src/de/pribluda/android/camerawatch/CameraAdapter.java
For better performance consider: