Android中Spinner中的关闭下拉列表
我需要在Android中打开和关闭微调器时设置箭头图标的动画。 打开微调器时,我可以旋转箭头:我只需在Android中Spinner中的关闭下拉列表,android,drop-down-menu,android-spinner,ontouchlistener,Android,Drop Down Menu,Android Spinner,Ontouchlistener,我需要在Android中打开和关闭微调器时设置箭头图标的动画。 打开微调器时,我可以旋转箭头:我只需在微调器上放置一个setOnTouchListener 当下拉列表关闭或隐藏时,问题就出现了,因为我不知道如何在该操作上设置侦听器或类似的内容 如果可能的话,有人知道怎么做吗 事先非常感谢。试试这种方法。 spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override
微调器上放置一个setOnTouchListener
当下拉列表关闭或隐藏时,问题就出现了,因为我不知道如何在该操作上设置侦听器或类似的内容
如果可能的话,有人知道怎么做吗
事先非常感谢。试试这种方法。
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
}
});
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView arg0、视图arg1、内部arg2、长arg3){
////在spiner关闭时调用
}
@凌驾
未选择公共无效(AdapterView arg0){
//spiner将关闭时调用
}
});
您可以这样做
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;
}
});
我不知道谷歌为什么不能这么久,但你可以这样解决问题:
您必须覆盖Spinner的受保护方法“OnAttachedFromWindow”,使其成为公共方法,并通过单击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。它仍然不起作用。当点击屏幕的任何部分时——因此Android关闭微调器——这不会触发。实现向下打开/关闭微调器的绝妙方法