在Android的下拉收盘在微调 [英] Closing dropdown in Spinner in Android
问题描述
我需要动画箭头的图标打开和Android中关闭微调时。
我可以在打开时微调旋转箭头:我只是把一个 setOnTouchListener
在微调
I need to animate an icon of an arrow when opening and closing a spinner in Android.
I can rotate the arrow when opening the spinner: I just put a setOnTouchListener
on the Spinner
.
问题来了,当下拉关闭,或隐藏,因为我不知道如何设置一个监听器或类似的东西在该操作。
The problem comes, when the dropdown is closed, or hidden, because I don't know how to set a listener or something like that on that action.
任何人有关于如何做到这一点的想法,如果可能的话?
Anybody has an idea about how to do this, if possible?
非常感谢在前进。
推荐答案
我不知道为什么谷歌不能做了这么久,但你能解决这个问题是这样的:
I do not know why Google can not do it for so long, but you can solve the problem this way:
您必须重写保护法onDetachedFromWindow的微调,使其作为公共方法,并通过单击该项目在CustomSpinnerAdapter唤起它。
You must override the protected method "onDetachedFromWindow" for Spinner, make it as public method, and calling forth it by clicking on the item in your CustomSpinnerAdapter.
例如:
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();
}
}
我希望你知道如何创建SpinnerCustomAdapter和XML插入此CustomSpinner。
I hope you know how to create SpinnerCustomAdapter and insert this CustomSpinner in xml.
这篇关于在Android的下拉收盘在微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!