开发者

handle onlongclicklistener of menus

开发者 https://www.devze.com 2023-03-03 14:18 出处:网络
I need to handle the selected row in listview on long click on the row but because am using menus I can\'t override the onclicklistener. I am trying to do this:

I need to handle the selected row in listview on long click on the row but because am using menus I can't override the onclicklistener. I am trying to do this:

开发者_开发知识库listView.setOnLongClickListener(new OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        taskPosition = listView.getSelectedItemPosition();
        return true;
    }
});

but it doesn't work. Can anyone help me?


i got the value of listView.getSelectedItemPosition(); is equal -1

Of course. Rows typically are not selected. Rows are only selected if the user is using a pointing device (D-pad, trackball, etc.).

i need to handle the selection longclick on listview and use it in onContextItemSelected to perform action

No, you don't. You either use context menus or you use a long-click listener with a widget. You do not use both.

If you are trying to determine what row was long-clicked from onContextItemSelected(), here is a sample project that will demonstrate that for you, if your adapter is an ArrayAdapter. If you are using a CursorAdapter, here is a different sample project that will demonstrate this for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号