I had an Alertbox show up when the user long presses on a spinner. It worked fine for Android 4.4 and below, but for Android L (5.0) the long click is not registering at all. Has anyone else seen this issue or have a workaround?
Here is the code
classArrayAdapter = new ArrayAdapter<String> (getApplicationContext(), R.layout.class_item, displayClassNames);
classArrayAdapter.setDropDownViewResource(R.layout.class_dropdown);
classSpinner = new Spinner(this);
classSpinner.setAdapter(classArrayAdapter);
classSpinner.setOnItemSelectedListener(new OnItemSelectedListener()
{
// spinner code here - spinner works fine
}
classSpinner.setOnLongClickListener(new OnLongClickListener()
{
@Override
public boolean onLongClick(View v)
{
if(UI==true)
{
studentsPresent();
}
else
{
studentsPassing();
}
return true;
}
});
You need to set
OnLongClickListener
on items of your adapter. Since I was usingArrayAdapter
, I had to subclass it and override the getView method like this:The
onLongClickListener
field is set in adapter's constructor.