异步填充列表视图上的 Android 上下文菜单
我有一个由 AsyncTask 填充的列表视图,我正在尝试创建一个上下文菜单...
@Override
public void onCreateContextMenu(ContextMenu menu,
View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int position = info.position;
ChannelShowItem myItem = (ChannelShowItem) aa.getItem(position);
menu.setHeaderTitle("TEST");
menu.add(0, 1, Menu.NONE, R.string.remove_item);
}
我可以运行该应用程序,但永远不会创建上下文菜单...另一方面,我尝试在列表视图上使用相同的代码它不是由 AsyncTask 填充的,并且工作正常...
我相信我必须在填充数据时创建上下文菜单,但我不知道如何...谢谢您的回答!
I have a listview which is filled by AsyncTask and I am trying to create a context menu....
@Override
public void onCreateContextMenu(ContextMenu menu,
View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int position = info.position;
ChannelShowItem myItem = (ChannelShowItem) aa.getItem(position);
menu.setHeaderTitle("TEST");
menu.add(0, 1, Menu.NONE, R.string.remove_item);
}
I can run the app, but context menu is never created... On the other hand I tried to use the same code on listview which isn't filled by a AsyncTask and it worked OK...
I believe that I have to create context menu when data is filled, but I don't know how... Thanks for you answer!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试重写
onPrepareContextMenu
,每次打开上下文菜单时都会调用此方法。希望这有帮助。Try overriding
onPrepareContextMenu
, this method is called every time the context menu is opening. Hope this helps.