I want to catch user interaction with a spinner like onCLickListener. Do to the ‘don’t call onClickListener() on AdapterView’ error I found recommendations that you should override a constructer with a custom spinner to set onClickListener() on the view the spinner creates.
Tried that:
public class MySpinner extends Spinner {
public static final String TAG = "MyApp";
public MySpinner(Context context, AttributeSet attrs) {
super(context, attrs);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.temp_systems, android.R.layout.simple_spinner_item);
TextView spinner_text = (TextView) findViewById(android.R.id.text1);
OnClickListener spinnerOnClickListener = new OnClickListener() {
public void onClick(View v) {
Log.d(TAG, "Should do something!");
}
};
spinner_text.setOnClickListener(spinnerOnClickListener);
setAdapter(adapter);
}
}
but when I try to include this in a layout I get a crash on failing to inflate this item.
To clarify here, onItemClickListener fires when the user clicks an item in the dropdown menu, not when the spinner is collapsed. I need to intercept after the initial spinner is clicked but before it creates the dropdown menu.
What they might mean is to
OverridethesetOnItemClickListenerand then call that in the constructor. So in yourmySpinnerclass you would need to add: [notice it is called on ITEM click listener, that might also be part of your issue]Dunno if that will fix your issue but I hope it helps. Good Luck.
also it might be worthwhile to possibly use