How to update SimpleAdapter in Android

后端 未结 5 1230
死守一世寂寞
死守一世寂寞 2020-12-19 04:06

Is it possible to update a SimpleAdapter? I have a list of data and a footer that says \"See Next Results\" When that list item is clicked I capture the event and get new d

5条回答
  •  一个人的身影
    2020-12-19 04:28

    Update: According to del116, you can indeed give SimpleAdapter a mutable map and then manually call the adapter's notifyDataSetChanged method when you need the list to update. However, my point below stands about the documentation of SimpleAdapter specifying that it is for static data; using it for mutable data is going counter to its design, so if you use this technique I would be sure to check on whether it continues to work in new Android releases as they emerge.

    (Original commentary follows:)

    If you look at the SimpleAdapter description it says it is "An easy adapter to map static data to views defined in an XML file." I've added the emphasis -- put simply, SimpleAdapater isn't built for use with data that changes; it handles static data only. If you can't use an ArrayAdapter because your data has more than a single bit of text, then you will either have to build your own custom ListAdapter, or put your data in a DB and use one of the CursorAdapters.

    As a last resort, if you don't need much performance, you could update a ListView backed by a SimpleAdapter by building a whole new SimpleAdapter instance any time your data changes and telling the list view to use it via setListAdapter.

提交回复
热议问题