Android Spinner Example : Getting started with Android
In Android, Spinner is nothing but a combo box or list box.
It lets you viewing multiple items and allows you to select one item from the list.
Edit Your XML code like this
1
2
3
|
Spinner android:id="@+id/Spinner01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
|
Your Java Class code should look like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public class TechnoCrunchSpinnerExample extends Activity {
private String array_spinner[];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
array_spinner=new String[5];
array_spinner[0]="1";
array_spinner[1]="2";
array_spinner[2]="3";
array_spinner[3]="4";
array_spinner[4]="5";
Spinner s = (Spinner) findViewById(R.id.Spinner01);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, array_spinner);
s.setAdapter(adapter);
}
}
|
The Output will look like
0
0