Unable to use LayoutInflater in custom adapter

后端 未结 4 1125
太阳男子
太阳男子 2021-01-02 10:48

I\'m looking into writing a custom adapter to populate a listview with 3 textviews per line. I\'ve found quite a bit of example code to do this, but the one that seemed the

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 11:07

    I'm a beginner also so take this answer with a pinch of salt - if it doesn't work, move on and Google some more. Not familiar with AdapterView since I traditionally have a ListView or GridView and a custom Adapter extended off a BaseAdapter and then listView.setAdapter(myCustomAdapter).

    You could try making something like this inside the WeatherAdapter class:

    public void addToList(Weather mWeather) {
        weatherList.add(mWeather);
    }
    

    Then in the class that calls WeatherAdapter:

    weatherAdapter.addToList(weatherToAdd);
    weatherAdapter.notifyDataSetChanged();
    

    Also you need to optimize it more in the getView method:

    http://www.youtube.com/watch?v=wDBM6wVEO70

提交回复
热议问题