2009-12-02 17 views

回答

1

我不知道我理解你的問題。如果你想在ListView中使用圖像,你需要爲你的列表項目定義一個自定義佈局。您可以在該佈局中放置ImageView,然後在您的getView或newView/bindView中(取決於您擴展的Adapter類),可以修改ImageView以包含您認爲合適的任何圖形。

+0

非常感謝 – deepthi 2010-02-16 10:55:46

1

請在/ RES一個新的文件/layout/demo.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/icon"/> 
    <TextView 
     android:id="@+id/os_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

在你的類file--

public class MyListActivity extends ListActivity { 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
    String[] values = new String[] { "Android", "iPhone", "WindowsMobile", 
      "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", 
      "Linux", "OS/2" }; 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
      R.layout.row, R.id.os_name, values); 
    setListAdapter(adapter); 
    } 
} 

在列表中,你會得到與圖像的文本。

相關問題