spinner in android example
6) Understand resource folders :
a. Create spinner with strings taken from resource folder(res >> value folder).
b. On changing spinner value, change image.
File Name : E6Activity.java
package bsr.exa;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
public class E6Activity extends Activity {
/** @author Bipin S Rupadiya , www.BipinRupadiya.blogspot.com
*
* 6) Understand resource folders :
* a. Create spinner with strings taken from resource folder(res >> value folder).
* b. On changing spinner value, change image.
**/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Spinner cmbSpinner = (Spinner)findViewById(R.id.cmbImg);
cmbSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
ImageView img=(ImageView)findViewById(R.id.img1);
String str=String.valueOf(cmbSpinner.getSelectedItem());
if(str.equals("Image-1"))
{
img.setBackgroundResource(R.drawable.bac);
img.setImageResource(R.drawable.icon);
}
else if(str.equals("Image-2"))
{
img.setBackgroundResource(R.drawable.bac);
img.setImageResource(R.drawable.android2);
}
else if(str.equals("Image-3"))
{
img.setBackgroundResource(R.drawable.bac);
img.setImageResource(R.drawable.android3);
}
else if(str.equals("Image-4"))
{
img.setBackgroundResource(R.drawable.bac);
img.setImageResource(R.drawable.android4);
}
else if(str.equals("Image-5"))
{
img.setBackgroundResource(R.drawable.bac);
img.setImageResource(R.drawable.android5);
}
else
{
img.setBackgroundResource(R.drawable.bac);
img.setImageResource(R.drawable.android1);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
String.xml
<?xml version="1.0"
encoding="utf-8"?>
<resources>
<string name="hello">www.BipinRupadiya.blogspot.com</string>
<string name="app_name">SL-MC, Exercise 6</string>
<string-array name="Android">
<item>Image-1</item>
<item>Image-2</item>
<item>Image-3</item>
<item>Image-4</item>
<item>Image-5</item>
<item>Image-6</item>
</string-array>
</resources>
Labels:
Android,
Mobile Computing
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Blog Archive
-
▼
2012
(79)
-
▼
September
(22)
- Chapter 7, Memory Management
- Chapter 6, Concurrency: Deadlock and Starvation
- Chapter 5, Concurrency: Mutual Exclusion and Sync...
- Chapter 4, Threads, SMP, and Micro kernels
- Chapter 3, Process Description and Control
- Chapter 2, Operating System Overview
- Chapter 1, Computer System Overview
- menu in android tutorial
- android animation example
- android chronometer example
- spinner in android example
- listview in android
- implicit intent in android example
- addTextChangedListener in Android example
- Be a Freelances and earn $$$$
- View SQLite Database
- Write a shell script to delete zero sized files fr...
- Android Intent Example
- Hello World in Android
- SQLite Android Tutorial
- Happy Teachers' Day
- Thank you GOD
-
▼
September
(22)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.