If you can only use a mobile phone, you can come here to learn about the following Android system for reference.
- // SpinnerDemo. java:
- Package com. cci. SpinnerDemo;
- Import android. app. Activity;
- Import android. OS. Bundle;
- Import android. view. View;
- Import android. widget. AdapterView;
- Import android. widget. AdapterView. OnItemSelectedListener;
- Import android. widget. ArrayAdapter;
- Import android. widget. Spinner;
- Import android. widget. TextView;
- Public class SpinnerDemo extends Activity {
- TextView TV;
- /** Called when the activity is first created .*/
- @ Override
- Public void onCreate (Bundle savedInstanceState ){
- Super. onCreate (savedInstanceState );
- SetContentView (R. layout. main );
- TV = (TextView) findViewById (R. id. mytxt );
- ArrayAdapter <String> adapter = new ArrayAdapter <String> (
- This, android. R. layout. simple_spinner_item );
- Adapter. setDropDownViewResource (
- Android. R. layout. simple_spinner_dropdown_item );
- // Whatever you want to write
- Adapter. add ("red ");
- Adapter. add ("green ");
- Adapter. add ("blue ");
- Spinner spinner = (Spinner) findViewById (R. id. myspinner );
- Spinner. setAdapter (adapter );
- Spinner. setOnItemSelectedListener (new OnItemSelectedListener (){
- Public void onItemSelected (AdapterView <?> Parent,
- View view, int position, long id ){
- Spinner spinner = (Spinner) parent;
- TV. setText (spinner. getSelectedItem (). toString ());
- // Log. v ("Test", "id =" + id + "("
- // + Spinner. getSelectedItem (). toString () + ")");
- }
- Public void onNothingSelected (AdapterView <?> Parent ){
- }
- });
- }
- }
-
- <! -- Main. xml -->
- <? 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"
- >
- <TextView
- Android: id = "@ + id/mytxt"
- Android: layout_width = "fill_parent"
- Android: layout_height = "wrap_content"
- Android: text = "@ string/hello"
- />
- <Spinner
- Android: id = "@ + id/myspinner"
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"
- > </Spinner>
- </LinearLayout>
Google intends to use new tools to solve the Android platform differentiation problem
Android Study Notes: androidmanifest. xml Parsing
Advanced Android development-Evaluation of proficient Android 2