如何在Android的更新SimpleAdapter [英] How to update SimpleAdapter in Android

查看:225
本文介绍了如何在Android的更新SimpleAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能更新SimpleAdapter?我有数据列表和页脚,说:看下结果当该列表项被点击我捕获事件,并获取新的数据。那么我想,以取代在这个新的数据ListView的数据,但我无法弄清楚如何做到这一点。有任何想法吗?我不想使用ArrayAdapter,导致只要我能看到的物品只能容纳一个字符串,我需要它来保存多个串和整数。

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 data. I then want to replace the data in the ListView with this new data but I can't figure out how to do it. Any Ideas? I don't want to use an ArrayAdapter, cause as far as I can see the items can only hold one string where I need it to hold multiple strings and ints.

推荐答案

更新的:根据del116,你的确可以给 SimpleAdapter 一个可变地图,然后手动调用适配器的 notifyDataSetChanged 方法,当你需要的名单进行更新。然而,我的观点如下身高约的SimpleAdapter指定它是静态数据的文件;将其用于可变数据会违背其设计,因此,如果你使用这个技术,我会一定要检查它是否继续在新的Andr​​oid版本中工作,因为他们出现。

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.

(原文评论如下:)

如果你看一下 SimpleAdapter描述它说,这是一个简单的适配器映射静态数据的在一个XML文件中定义的意见。我已经添加了强调 - 简单地说, SimpleAdapater 不是为与变化的数据使用;它只能处理静态数据。如果你不能使用 ArrayAdapter 的,因为你的数据已经超过了文本的单个位,那么你将不得不建立自己的自定义 ListAdapter ,或者把你的数据在DB和使用的一个<一个href="http://developer.android.com/reference/android/widget/CursorAdapter.html">CursorAdapters.

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.

作为最后的手段,如果你并不需要太多的表现,你的可以的更新的ListView SimpleAdapter 通过建立一个全新的 SimpleAdapter 实例中的任何时候你的数据变化,并告诉列表视图通过 setListAdapter使用它

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.

这篇关于如何在Android的更新SimpleAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆