context menu android
i have a listactivity in android. A context menu open when i press an item of my listview.
The problem occurs when i close this context menu and i back to press the same item (the other 开发者_StackOverflow社区items have no problems)
if i press into the text, the context menu doesn't open, but if i press in white area then the contextmenu appears.
¿what's the problem?
oncreate method:
lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView text = (TextView) view.findViewById(R.id.label);
if (!text.getTag().toString().equals("-1"))
{
registerForContextMenu(text);
openContextMenu(text);
}
}
});
If you want a context menu for your ListView
, call registerForContextMenu()
in onCreate()
of your activity, passing in the ListView
. Here is a sample project demonstrating this, including showing how to determine which particular row in the ListView
the user long-tapped upon to bring up the context menu.
精彩评论