2011-06-10 23 views
6

benim özel ListView ile sorun var.Custom ListView Android

SimpleAdapter adapter = new SimpleAdapter(this, 
    this.dh.selectAll(), 
    R.layout.custom_row_view, 
    new String[] {"Icon","Chance","TeamID"}, 
    new int[] {R.id.text1,R.id.text2, R.id.text3}); 
    setListAdapter(adapter); 

Bu benim basit bağdaştırıcım. Onlara simgeleri koymak istiyorum, bunu yapabilir miyim?

+1

Eğer SO veya Google burada soru göndermeden önce googled sığınak görünüyor. –

+0

evet ama daha spesifik olması gerektiğini olabilir ... nasıl Wana simgesini sağlıyorsunuz? Uri tarafından? kaynak kimliği o cevaplar için tembel görüntü yükleme – Selvin

+0

@Kartik biz aslında birçok simgelerle klasörü (çekilebilir/bayrakları/Albania.png) var ve benim simpleadapter – Selvin

cevap

21

evet yapabilirsiniz ...

MyList.java:

package com.TestActivity; 

import java.util.ArrayList; 
import java.util.HashMap; 

import android.app.ListActivity; 
import android.os.Bundle; 
import android.widget.SimpleAdapter; 


public class MyList extends ListActivity { 

    final static ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(); 

    static{ 
     HashMap<String, Object> row = new HashMap<String, Object>(); 
     row.put("Icon", R.drawable.flags_albania); 
     row.put("Chance", "65%"); 
     row.put("TeamID", "Albania"); 
     data.add(row); 
     row = new HashMap<String, Object>(); 
     row.put("Icon", R.drawable.flags_rpa); 
     row.put("Chance", "55%"); 
     row.put("TeamID", "RPA"); 
     data.add(row); 
     row = new HashMap<String, Object>(); 
     row.put("Icon", R.drawable.flags_polska); 
     row.put("Chance", "100%"); 
     row.put("TeamID", "Polska :)"); 
     data.add(row); 
    } 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     SimpleAdapter adapter = new SimpleAdapter(this, 
       data, 
        R.layout.row, 
        new String[] {"Icon","Chance","TeamID"}, 
        new int[] { R.id.imageView1, R.id.textView1,R.id.textView2}); 
     setListAdapter(adapter); 

    } 
} 

res/düzen/row.xml: res için bayraklarıyla

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon" android:id="@+id/imageView1"/> 
    <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 
    <TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 
</LinearLayout> 

koymak pngs/çekilebilir-hdpi/

flags_albania.png flags_rpa.png flags_polska.png

ve böyle smthing alacak:

enter image description here