如何从通用适配器调用notifyDataSetChanged()
ListView
的 OnItemClickListener
具有以下方法:
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
我希望在 ListView
刷新后面使用适配器,并且我相信这已经完成通过使用:
BaseAdapter.notifyDataSetChanged()
如何使用 onItemClick
方法中的 parent
参数来执行此操作?到目前为止,我已经尝试过:
parent.getAdapter().notifyDataSetChanged();
这会引发错误,因为返回的对象属于 HeaderViewListAdapter
类,由于未知的原因,它不是 BaseAdapter
的子类。
An OnItemClickListener
for a ListView
has the following method:
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
I'd like to have the adapter behind the ListView
refresh, and I believe this is done through the use of:
BaseAdapter.notifyDataSetChanged()
How do I use the parent
parameter in the onItemClick
method to do this? So far I've tried:
parent.getAdapter().notifyDataSetChanged();
This throws an error because the object returned is of class HeaderViewListAdapter
, which for reasons unknown isn't a subclass of BaseAdapter
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您还可以通过自定义适配器访问 BaseAdapter,如以下代码片段所示:
You can also get to the BaseAdapter via your custom adapter as show in the following code fragment:
AFAIK,HeaderListView 中没有任何方法用于数据刷新/重新加载。我能想到的唯一方法是重新分配适配器。
AFAIK, there isn't any method in HeaderListView for data refresh/reload. The only way I can think of doing this is to reassign the adapter.
使用光标时,不需要调用任何方法来刷新适配器客户端。
相反,在执行任何操作后,您必须使用 getContentResolver().notifyChange(uri, null); 来“通知更改”
例如:
您的 viewclient(Listview、Gridview 等) 无论您是否使用自定义适配器,都会自动更改。
希望这有帮助。
You don't need to call any method to refresh your adapter client when you work with cursor.
Instead, after any operation you have to "Notify the changes" using
getContentResolver().notifyChange(uri, null);
For example:
Your
viewclient (Listview, Gridview, Whatever)
will change automatically even you're using a custom adapter or not.Hope this help.
我发现更简单的方法..只需调用
this.onCreate(null)
即可重新加载完整的创建方法,但活动保持不变。I found much easier way ..just call
this.onCreate(null)
that will reload complete create method but the activity remains same .