Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to tell is someone has pressed a SPINNER but not changed the visible item in it

I have a spinner, which mostly works. If a user selects one of the items in it, the 'onItemSelected' routine catches it just fine.

But if a user clicks the same spinner, but does not change from the already visible item that it's currently displaying, the 'onItemSelected' routine just ignores it, and the logs show:-

WARN/InputManagerService(577): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@437948b0

I there anyway to capture someone doing this? The idea is that my spinner contains a list of names, and when a user selects one from the spinner, it gets added to a listview.

I could just add another button to get the name from the spinner, but, screen-space is already lacking and I'd rather not add anymore content.

like image 451
andy_spoo Avatar asked Nov 20 '25 18:11

andy_spoo


1 Answers

This problem could be solved with overriding Spinner.onClick(), but this is buggy from android 3.0 and above (Spinner.onClick() is called on 2.2 device, not called on 3.0 device).

So the best solution is the AlertDialog.Builder as @adamp said.

AlertDialog.Builder builder = new Builder(this);
// maybe get from resources 
CharSequence titles[] = getResources().getTextArray(R.array.titles);
builder.setItems(titles, new DialogInterface.OnClickListener() {
  @Override
  public void onClick(DialogInterface dialog, int which) {
    // add your code here               
  }
});
builder.create().show();
like image 188
sotcha Avatar answered Nov 23 '25 07:11

sotcha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!