我想在单击Android微调器外部后关闭该微调器。这有可能吗?
发布于 2011-10-19 05:34:21
试一试
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) v.setVisibility(View.GONE);
}发布于 2012-02-21 15:51:38
我在这方面有一些运气,即使它不能完全工作。
微调器适配器的get视图:
public View getView(int position, View v, ViewGroup parent) {
if (v == null) {
LayoutInflater mLayoutInflater = mActivity.getLayoutInflater();
v = mLayoutInflater.inflate(R.layout.user_row, null);
}
View tempParent = (View) parent.getParent().getParent().getParent();
tempParent.setOnTouchListener(new MyOnTouchListener(mActivity));
mActivity.setOpen(true);
User getUser = mUsers.get(position);
return v;
}ontouch监听器:
public class MyOnTouchListener implements OnTouchListener{
private MyActivity mOverall;
public MyTouchListener(MyActivity overall) {
mOverall = overall;
}
public boolean onTouch(View v, MotionEvent event) {
if (mOverall.getOpen()) {
mOverall.getWindow().setContentView(R.layout.main); //reset your activity screen
mOverall.initMainLayout(); //reset any code. most likely what's in your oncreate
}
return false;
}
}on item selected监听程序:
public class MySelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
setUser(pos); //or whatever you want to do when the item is selected
setOpen(false);
}
public void onNothingSelected(AdapterView<?> parent) {}
}活动
使用微调器的activity应该有一个带有get和set方法的全局变量mOpen。这是因为ontouch侦听器即使在列表关闭后也会保持打开状态。
此方法的局限性:
如果在微调器和选项之间进行触摸,或者触摸到选项的一侧,它将关闭。触摸微调器上方和下方的选项仍然不会关闭它。
发布于 2013-10-21 23:43:52
我希望能够确定微调器菜单何时显示,以及何时关闭。经过大量的搜索,没有太多好的解决方案。通过执行以下操作,我能够做到这一点:
@Override public boolean performClick() { this.isDropDownMenuShown = true;//标志指示微调器菜单显示return super.performClick();}
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged( hasFocus);if (actionBarSpinner.isDropdownShown() && hasFocus){ actionBarSpinner.setDropdownShown(false);//您在这里工作}
}
祝好运!
https://stackoverflow.com/questions/7415970
复制相似问题