How to pass variables on long press on ListView?

后端 未结 2 523
终归单人心
终归单人心 2021-01-24 06:54

I would have listview and a lot of items inside. I want that user can long press on item and set it as Favorite. To do that, I need to get DB id to this menu on long press.

2条回答
  •  粉色の甜心
    2021-01-24 07:46

    If your adapter supports getting Id, so it should look like this:

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
        long id = menuInfo.id;
        ...
    

提交回复
热议问题