Pregunta

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, ?>>' or 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/

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top