Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to capture long press event for Listeview item of a ListActivity?

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.

like image 591
saiket Avatar asked May 26 '11 16:05

saiket


1 Answers

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;     } }); 
like image 72
user809486 Avatar answered Oct 06 '22 00:10

user809486