I am trying to make the Spinner behave different way when the user clicked on an item for a long time. I have spinner with some project and I want two things.
- When the user simple click on an item I want to normal select it.
- When the user have long clicked on an item I want to show dialog, with options like "Edit item", "Delete item".
The first step works well (ofcourse), but when I am trying to do the second task I can not make spinner to generate longClicked event.
Here is my code:
this.projectSpinner = (Spinner) this.findViewById(R.id.SpinnerProjects);
this.projectSpinner.setLongClickable(true);
this.projectSpinner.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){
public boolean onItemLongClick(AdapterView<?> arg0,
View arg1,
int arg2,
long arg3) {
Toast.makeText(
AndroidTimeTrackerMainActivity.this,
"Long click",
Toast.LENGTH_SHORT).show(); // This toast doesn't show up.
return false;
}
});
1) Create a custom spinner class by extending spinner,
Use the above spinner in your xml view.
2) Define an interface to handle clicks,
3) In your spinner adapter class do these stuffs in getView and getDropDownView
4) While instantiating the adapter, pass the ClcikListener interface we created.
5) and in the implementing class do the following,
The
Spinner
currently does not supportOnItemLongClickListener
.You can add an OnLongClickListener to the Spinner though. It wont be fired when an item on the menu is long clicked but it will be fired when the user long clicks the spinner itself.
simply use an touchlistener with handler. for getting selected item