Roger
Roger

Reputation: 4259

Multiple longclicklisteners

I have 10 items that when long clicked, will bring up an item specific dialog. This is not a listview.

Right now, I'm registering a long click listener on every item. Is it possible to capture the view of the long clicked item much like you can set android:onClick="buttonClick" and in code have public void buttonClick(View v), where you can then identify the clicked button using v?

Upvotes: 0

Views: 93

Answers (1)

Sunil Pandey
Sunil Pandey

Reputation: 7102

you can

create a class implements longclicklistener

and override it like

private class MyOnClickListener implements OnLongClickListener{
    @Override
    public void onLongClick(View v){
       id=v.getId();
       switch(id){
         case R.id.item1:
            //your item1 code
         case R.id.item2:
           //your item 2 code
       }
    }
}

declare it as your inner class for convenience of accessing your values

Upvotes: 3

Related Questions