Android项目中的ArrayAdapter

Android项目中的ArrayAdapter,android,Android,可能重复: 您必须从适配器派生,并提供正确填充的视图。就像这里: 要获得更好的性能,请考虑: 重用提供给getView()方法的视图# 使用viewHolder Patrn保存getViewById()分辨率 不,它不是上述质量保证的副本。这里的问题是如何在没有光标的情况下工作,这里的问题是如何放置字符串。 ArrayAdapter<String> adapter = null; JSONArray productsList = null; try { products

可能重复:


您必须从适配器派生,并提供正确填充的视图。就像这里:

要获得更好的性能,请考虑:

  • 重用提供给getView()方法的视图#
  • 使用viewHolder Patrn保存getViewById()分辨率

不,它不是上述质量保证的副本。这里的问题是如何在没有光标的情况下工作,这里的问题是如何放置字符串。
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)