I have a listview, on click appears a context menu. Any way to know the context menu over which listview item appeared?

StackOverflow https://stackoverflow.com/questions/21145633

Вопрос

Have a listview, on click appears a context menu. Any way to know the context menu over which listview item appeared?

Это было полезно?

Решение

int listViewPosition;
listview.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
        listViewPosition = position;
    }
 });

Then you can use listViewPosition in

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo){
    Log.d("ListView clicked Item", ""+listViewPosition);
    // rest of code
}

Другие советы

You get the selected item from the listview:

lv.getSelectedItem()

You can use:

listview.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {

    }
 });

Where position is the position of the item that was clicked in the ListView.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top