Search code examples
androidlistviewonlongclicklistener

advice needed with ListVew


My activity has a ListView .Now suppose you have a long type variable 'id_item_clicked'. And a variable of ListView type i.e. 'list' . Now suppose you long clicked an item in the list view. Would id_item_clicked = list.getId(); initialise the id of the item long clicked to the variable id_item_clicked? could someone help me with this? thanks.


Solution

  • getId() will retrieve the ID of the ListView itself, not the view you long pressed on. Docs for View.getId()

    If you want to get Id of the view you long pressed on I suggest implementing an OnItemLongClickListener in your activity and using the ID parameter from that