解决方法
我有一些运气,即使它不能完全奏效.
微调适配器的获取视图:
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; }
本体聆听者:
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; } }
在项目选择的听众:
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) {} }
活动
您使用微调器的活动应该有一个全局变量mOpen与get和set方法.这是因为即使列表关闭后,该套头倾听者倾向于保留.
这种方法的局限性: