机器人:刷新的ListView使用ListAdapter和SimpleCursorAdapter [英] android: Refresh ListView using ListAdapter and SimpleCursorAdapter

查看:152
本文介绍了机器人:刷新的ListView使用ListAdapter和SimpleCursorAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图刷新使用创建为SimpleCursorAdapter一个ListAdapter一个ListView。

I'm trying to refresh a ListView that uses a ListAdapter created as a SimpleCursorAdapter.

下面是我的$ C $下创建光标和ListAdapter中的onCreate其中填充的ListView。

Here is my code for creating the Cursor and ListAdapter in onCreate which populates the ListView.

tCursor = db.getAllEntries();       

ListAdapter adapter=new SimpleCursorAdapter(this,
                R.layout.row, tCursor,
                new String[] columns,
                new int[] {R.id.rowid, R.id.date});

setListAdapter(adapter);

然后,我的一些数据添加到另一种方法分贝,但我无法弄清楚如何刷新的ListView。在计算器和其他地方类似的问题提用notifyDataSetChanged(),并重新查询(),但也不是ListAdapter或SimpleCursorAdapter的方法。

Then, I add some data to the db in another method, but I can't figure out how to refresh the ListView. Similar questions on stackoverflow and other places mention using notifyDataSetChanged() and requery(), but neither are methods of ListAdapter or SimpleCursorAdapter.

推荐答案

我能够得到的ListView通过创建一个新的适配器,并再次呼吁setListAdapter刷新。

I'm able to get the ListView to refresh by creating a new adapter and calling setListAdapter again.

我把它命名为适配器2中的另一种方法。

I named it adapter2 in the other method.

tCursor = db.updateQuery();       

ListAdapter adapter2=new SimpleCursorAdapter(this,
                R.layout.row, tCursor,
                columns,
                new int[] {R.id.rowid, R.id.date});

setListAdapter(adapter2);

我不知道为什么这是必要的,但它适用于现在。如果任何人有一个更好的解决方案,我愿意尝试一下。

I'm not sure why this is necessary, but it works for now. If anyone has a better solution, I'm willing to try it.

这篇关于机器人:刷新的ListView使用ListAdapter和SimpleCursorAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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