Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've had some luck with this, even if it doesn't completely work.</p> <h2>The spinner adapter's get view :</h2> <pre><code>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; } </code></pre> <h2>The ontouch listener :</h2> <pre><code>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; } } </code></pre> <h2>The on item selected listener :</h2> <pre><code>public class MySelectedListener implements OnItemSelectedListener { public void onItemSelected(AdapterView&lt;?&gt; 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&lt;?&gt; parent) {} } </code></pre> <h2>The activity</h2> <p>Your activity with the spinner should have a global variable mOpen with get and set methods. This is because the ontouch listener tends to stay on even after the list is closed.</p> <h2>The limitations of this method:</h2> <p>It closes if you touch between the spinner and the options or to the side of the options. Touching above the spinner and below the options still won't close it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload