Wednesday, January 6, 2010

Android Spinner Example

In Android, Spinner is nothing but combo box or list box.

Viewing multiple items and selecting one item from the list.

Edit Your XML code like this


android:layout_width=”wrap_content”

android:layout_height=”wrap_content” />

Edit Your Java Class code like this

public class SpinnerExample 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 looks like

[Via http://androidpeople.wordpress.com]

No comments:

Post a Comment