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.
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;
}
});
The Spinner
currently does not support OnItemLongClickListener
.
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.
this.projectSpinner.setOnLongClickListener(new OnLongClickListener()
{
@Override
public boolean onLongClick(View v)
{
System.out.println(chuteSpinner.getSelectedItem().toString() + " is long clicked");
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