lets assume i have a ListActivity , now i want catch the long press event on a list item , for that i used following block of code (get after googled) but it's not working!!! please help!
public class InboxActivity extends ListActivity { this.getListView().setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(InboxActivity.this, "postion: " + getListView().getSelectedItemPosition(), Toast.LENGTH_SHORT).show(); return true; } }); }
I also see some code in online with contextmenu but there i dont get way of getting the position of listItem from where the context menu open.
I dont know if you already solved you problem, im almost sure you did, but this works
this.getListView().setLongClickable(true); this.getListView().setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) { //Do some return true; } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With