Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could switch the activity's entire content view to a new view or layout resource in your <code>onItemSelected</code> callback by using <a href="http://developer.android.com/reference/android/app/Activity.html#setContentView%28android.view.View%29" rel="noreferrer"><code>Activity.setContentView()</code></a>, but I expect that isn't quite what you want as it would replace the spinner itself.</p> <p>How about adding/replacing a child view into your activity's content view? This could be a view inflated from an XML resource, and they could share some view IDs to cut down on the code required (or you could delegate the behaviour to separate classes).</p> <p>For example:</p> <p><code>main.xml</code>:</p> <pre><code>&lt;LinearLayout ...&gt; &lt;!-- Root element --&gt; &lt;!-- Put your spinner etc here --&gt; &lt;FrameLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/search_criteria_area" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><code>search1.xml</code>:</p> <pre><code>&lt;!-- Contents for first criteria --&gt; &lt;LinearLayout ...&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ffff0000" android:id="@+id/search_content_text" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><code>search2.xml</code>:</p> <pre><code>&lt;!-- Contents for second criteria --&gt; &lt;LinearLayout ...&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ff00ff00" android:id="@+id/search_content_text" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Then in your activity, you could switch between them like so:</p> <pre><code>public class SearchActivity extends Activity { // Keep track of the child view with the search criteria. View searchView; @Override public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) { ViewGroup searchViewHolder = (ViewGroup)findViewById(R.id.search_criteria_area); if (searchView != null) { searchViewHolder.removeView(searchView); } int searchViewResId; switch(position) { case 0: searchViewResId = R.layout.search1; break; case 1: searchViewResId = R.layout.search2; break; default: // Do something sensible } searchView = getLayoutInflater().inflate(searchViewResId, null); searchViewHolder.addView(searchView); TextView searchTextView = (TextView)searchView.findViewById(R.id.search_content_text); searchTextView.setText("Boosh!"); } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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