How do I get the row ID of the row from a ListView, which contains a clickable item?

前端 未结 2 585
离开以前
离开以前 2021-01-14 11:25

Before I added a button to the layout XML for my rows, the row ID was returned in the callback onListItemClick() upon a list item being clicked. Now that I added a button to

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 12:07

    You can tag your Buttons with the appropriate id or position in your adapter's getView method. For example:

    myButton.setTag(id);
    

    Then in your onClick handler, retrieve the tag from the view that was clicked. For example:

    public void newCallBackFunctionName(View v) {
        long id = (Long) v.getTag();
        // ...
    }
    

提交回复
热议问题