简体   繁体   中英

Android SimpleAdapter - Asking to change type of List<Map>

I am implementing a SimpleAdapter like this:

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

However, 2nd line gives me this error:

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

Two fixes

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

I Chose the Cast option, but this then only showed the icons for the drawer list items, not their TextView labels...

I followed this tutorial: http://shenhengbin.wordpress.com/2012/03/17/listview-simpleadapter/

I resorted to using a Custom Adapter as per this example. I ran into an error ("Variable must provide either dimension expressions or an array") with this bit in that link:

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

I changed this to Weather weather_data[] = new Weather[NUM_OF_ITEMS] to fix it :) Hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM