2012-12-20 3 views
0

Possible en double:
Adapter for a custom layout of listviewArrayAdapter dans le projet Android

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); 
} 

Voici mon avis la liste:

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_margin="5dip" 
    android:layout_weight="30"> 
</ListView> 

Et voici comment je passe chaque produit séparément . Maintenant, et selon le code mentionné ci-dessus, je passe à chaque ligne juste une simple chaîne.

<?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> 
Cependant, je me demandais comment je pouvais passer trois chaînes différentes. La raison pour laquelle je veux passer trois cordes est que je veux qu'ils soient dans le format suivant:

Quantity X 
Number       Price(this should be at the end of the line) 
+0

Non , ce n'est PAS un duplicata du QA mentionné. La question est de savoir comment travailler sans curseur, la question ici - comment placer la chaîne. – Gangnus

Répondre