2013-08-31 53 views
0

我實現一個SimpleAdapter喜歡這個列表的類型:的Android SimpleAdapter - 要求更改<Map>

List<Map> data = getDrawerData(); 
    SimpleAdapter adapter = new SimpleAdapter(this, data,R.layout.drawer_list_item,new String[] {"drawer_icon","drawer_text"},new int[] {R.id.drawer_icon, R.id.drawer_text}); 

然而,2號線給了我這個錯誤:

The constructor SimpleAdapter(MainActivity, List, int, String[], int[]) is undefined

Two fixes

1. Cast argument 'data' to 'List<? extends Map<String, ?>>'2. Change type of 'data' to 'List<? extends Map<String, ?>>'

我選擇了Cast選項,但這則僅顯示圖標抽屜列表項,而不是他們TextView標籤...

我跟着這個教程:http://shenhengbin.wordpress.com/2012/03/17/listview-simpleadapter/

+0

通過extendng創建自定義適配器ArrayAdapter –

+0

您是否導入'SimpleAdapter' ...'import android.widget.SimpleAdapter;' – bakriOnFire

+0

'@ Biraj'有沒有辦法可以使用'SimpleAdapter'? – KickAss

回答

0

我轉向使用自定義適配器按照this的例子。我遇到了一個錯誤(「變量必須提供尺寸表達式或數組」),在該鏈接該位:

Weather weather_data[] = new Weather[] // << HERE 
    { 
     new Weather(R.drawable.weather_cloudy, "Cloudy"), 
     new Weather(R.drawable.weather_showers, "Showers"), 
     new Weather(R.drawable.weather_snow, "Snow"), 
     new Weather(R.drawable.weather_storm, "Storm"), 
     new Weather(R.drawable.weather_sunny, "Sunny") 
    }; 

我改變了這Weather weather_data[] = new Weather[NUM_OF_ITEMS]解決它:) 希望這可以幫助別人。