2011-05-31 29 views
1

我最近使用ListAdapter創建了一個ListView,並在列表後面應用了一個靜態背景圖像;使用SimpleAdapter對ListView應用背景圖像

String[] teams = getResources().getStringArray(R.array.array); 
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_view, teams)); 

    ListView lv = getListView(); 
    lv.setTextFilterEnabled(true); 

    lv.setBackgroundResource(R.drawable.football_turf_subtle); 

    lv.setCacheColorHint(0); 

我現在正在切換到使用SimpleAdapter在每個列表項目中包含各種項目。

setContentView(R.layout.custom_list_view); 

    SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.row_view, 
    new String[] {"pen","price","color"}, 
    new int[] {R.id.text1,R.id.text2, R.id.text3}); 

    populateList(); 

    setListAdapter(adapter); 

僅供參考,以上列表中的項目來自我找到的示例。我遇到的問題是我不知道如何應用背景圖像,因爲我以前使用過ListAdapter版本。 (即setBackgroundResource)

任何幫助,將不勝感激!

回答

1
<ListView android:cacheColorHint="#00000000" android:textSize="10dip" 
    android:dividerHeight="1dip" 
    android:smoothScrollbar="true" android:background="@drawable/worldmap4" 
    android:id="@+id/ListView01" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:clickable="true" 
    android:drawingCacheQuality="auto" android:fastScrollEnabled="true" 
    android:footerDividersEnabled="true" android:focusableInTouchMode="true" 
    android:isScrollContainer="true" android:keepScreenOn="true" 
    android:scrollbarStyle="outsideOverlay"></ListView> 

的android:背景=「@繪製/ worldmap4」 在XML文件中就使用了設置的ListView的靜態背景添加此元素。 我希望這是幫助。

0

該方法完全相同。無論您使用的適配器類型如何,您設置的背景資源都應用於ListView。

我有一個使用SimpleCursorAdapter的3 TextView的自定義列表項,它使用setCacheColorHint(0)在ListView上設置背景資源時工作正常。