Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Spinner.xml :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawSelectorOnTop="true" /&gt; &lt;ImageView android:id="@+id/myimgview" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt;&lt;/ImageView&gt; &lt;/LinearLayout&gt; </code></pre> <p>Your Activity Class must look like this :</p> <pre><code>package my.co.home; import android.app.Activity; import android.content.Intent; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener; public class ViewsActivity extends Activity { String[] presidents = { "January", "February", "March", "December" }; Spinner s1; ImageView ivl; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //startActivity(new Intent(this, SpinnerActivity.class)); s1 = (Spinner) findViewById(R.id.spinner1); ivl=(ImageView) findViewById(R.id.myimgview); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, presidents); s1.setAdapter(adapter); s1.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { int index = s1.getSelectedItemPosition(); //Depending on index you display the image..For example i have taken for //two indexes if(index==1) ivl.setBackgroundDrawable(getResources().getDrawable(R.drawable.images)); else if(index==2) ivl.setBackgroundDrawable(getResources().getDrawable(R.drawable.images1)); } public void onNothingSelected(AdapterView&lt;?&gt; arg0) {} }); } } </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. This table or related slice is empty.
    1. 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