7

I am using a loading spinner animation with a set of items. If you click outside of it, then it should disappear. Does anybody know how to do this?

Spinner

I have tried this. It's working with EditText. But it's not working for Spinner

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    View view = getCurrentFocus();
    boolean ret = super.dispatchTouchEvent(event);

    if (view instanceof EditText||view instanceof Spinner) {
        View w = getCurrentFocus();
        int scrcoords[] = new int[2];
        w.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + w.getLeft() - scrcoords[0];
        float y = event.getRawY() + w.getTop() - scrcoords[1];

        if (event.getAction() == MotionEvent.ACTION_UP 
 && (x < w.getLeft() || x >= w.getRight() 
 || y < w.getTop() || y > w.getBottom()) ) { 
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }
    }
 return ret;
}

Thanks in Advance.

Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78

2 Answers2

1

What I personaly did was to create a custom AlertDialog with setSingleChoiceItems() to do the same thing. Then I used setCanceledOnTouchOutside().

shkschneider
  • 17,833
  • 13
  • 59
  • 112
  • thanks for the answer. I tried it in my previous application and succeed too. But Here my requirement is for spinner. not for a AlertDialog. if you know help me pls – Ram kiran Pachigolla Nov 27 '12 at 13:35
  • You can just catch the `Spinner` action `onClick()` and run an `AlertDialog` I don't see what's difficult. – shkschneider Nov 27 '12 at 14:24
0

There's a solution for Dialog link

So why don't you try to create a custom dialog (simple example) which will looks like a spinner? Create a layout file for your dialog with radiobuttons.

When user clicks a radiobutton, call dialog.dismiss() and do necessary code next

Community
  • 1
  • 1
Ilya Blokh
  • 11,923
  • 11
  • 52
  • 84