-
Create new Android Project and fill all require details.
-
Open String.xml file under resources folder and modify as below.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">SpinnerDemo Idroid</string>
<string name="item_list">Select Picture</string>
<string-array name="spinner">
<item>Picture1</item>
<item>Picture2</item>
<item>Picture3</item>
</string-array>
</resources>
-
Open your main.xml file and simply change design display as above layout one Spinner top of the screen and below display ImageView for that you need to modify main.xml file under layout folder.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/spinner"
android:prompt="@string/item_list"
android:id="@+id/spin1"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imgv1"/>
</LinearLayout>
-
Now put three images in res>drawable folder particular size which you want to display and also give proper name for images after that modify your MainActivity.java file given below.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/spinner"
android:prompt="@string/item_list"
android:id="@+id/spin1"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imgv1"/>
</LinearLayout>
No comments:
Post a Comment