Closing the Spinner drop-down list in Android

I need to animate an arrow icon when opening and closing a counter in Android. I can rotate the arrow when I open the counter: I just put setOnTouchListener on the Spinner .

The problem arises when the popup is closed or hidden because I donโ€™t know how to install a listener or something like that in this action.

Does anyone have an idea how to do this, if possible?

Thank you very much in advance.

+1
source share
3 answers

I donโ€™t know why Google cannot work for so long, but you can solve this problem as follows:

You must override the protected method "onDetachedFromWindow" for Spinner, make it public and call it by clicking on the item in the CustomSpinnerAdapter.

For example:

  public class CustomSpinner extends Spinner { Context context = null; public CustomSpinner(Context context) { super(context); } public CustomSpinner(Context context, int mode) { super(context, mode); } public CustomSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public CustomSpinner(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public CustomSpinner(Context context, AttributeSet attrs, int defStyle, int mode) { super(context, attrs, defStyle, mode); } @Override public void onDetachedFromWindow() { super.onDetachedFromWindow(); } } 

Hope you know how to create a SpinnerCustomAdapter and insert this CustomSpinner in xml.

+2
source

You can do something like this,

  boolean bflag=true;//declare it as public spinner.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { // TODO Auto-generated method stub if(bflag==true) { //first animation code goes here Toast.makeText(getActivity(), "on", Toast.LENGTH_SHORT).show(); bflag=false; } else { //second animation code goes here Toast.makeText(getActivity(), "off", Toast.LENGTH_SHORT).show(); bflag=true; } return false; } }); 
+1
source

try this way

 spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // // called when spiner will closed } @Override public void onNothingSelected(AdapterView<?> arg0) { // called when spiner will closed } }); 
0
source

All Articles