Try looking at:
AdapterView.onItemLongClick()
ListView implements AdapterView, so you'll have access to that juicy
method, which will pass the id of the item clicked as well as the
item's view the same as with onListItemClick().
{begin code}
// ListActivity has a ListView, which you can get with:
ListView lv = getListView();
// Then you can create a listener like so:
lv.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener
(){
@Override
public boolean onItemLongClick(AdapterView<?> av, View v, int
pos, long id) {
onLongListItemClick(v,pos,id);
return false;
}
});
// You then create your handler method:
protected void onLongListItemClick(v,pos,id) {
Log.i( TAG, "onLongListItemClick id=" + id );
}
{end code}
The standard onListItemClick() will still fire as well; my best guess
there is to keep a suppression boolean around, which isn't pretty.
Any other thoughts on this?
Phrases I searched for before finally stumbling across the proper
docs:
listactivity hold
listactivity longclick
android list long click
listactivity long click
listactivity long touch
android listview onLongClickListener
On Jan 2, 4:04 am, "[email protected]" <[email protected]>
wrote:
> Hi,
>
> Maybe this can help:
>
> @Override
> public void onCreateContextMenu(ContextMenu menu, View view,
> ContextMenuInfo menuInfo) {
> AdapterView.AdapterContextMenuInfo info;
> try {
> info = (AdapterView.AdapterContextMenuInfo) menuInfo;
> } catch (ClassCastException e) {
> Log.e(TAG, "bad menuInfo", e);
> return;
> }
>
> long l = getListAdapter().getItemId(info.position);
> }
>
> On Dec 1 2008, 7:12 pm, Thao <[email protected]> wrote:
>
> > Hi all,
>
> > I have an Activity that implements a ListActivty. In there, I have a
> > list of item that is wrapped by a custom adapter.
>
> > I would like to enable long click on each item in my list, but I can't
> > figure out how to do this...Could someone give an example please ?
>
> > Thank.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---