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);
}以下是我的列表视图:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dip"
android:layout_weight="30">
</ListView>下面是我如何分别传递每种产品的方法。
<?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>现在,根据前面提到的代码,我只传递给每一行一个简单的字符串。然而,我想知道我如何通过三个不同的字符串。我想传递三个不同的字符串的原因是我希望它们的格式如下:
Quantity X
Number Price(this should be at the end of the line)发布于 2012-12-20 10:04:31
您必须从适配器派生,并提供适当填充的视图。就像这里:
为了取得更好的业绩,请考虑:
https://stackoverflow.com/questions/13969387
复制相似问题