Functions and usage of the Android self-learning Notes-based Spinner drop-down box
Spinner:
Is a type of control similar to the drop-down list. You can select the corresponding option!
The data in the Spinner needs to be filled with an Adapter.
Usage:
Layout file activity_main.xml:
<span style="font-family:KaiTi_GB2312;font-size:18px;"><Spinner android:id="@+id/spinner" android:layout_width="match_parent" android:layout_height="wrap_content" ></Spinner> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" /></span>
Class file MainActivity. java:
<Span style = "font-family: KaiTi_GB2312; font-size: 18px;"> package com. example. administrator. spinner1; import android. support. v7.app. actionBarActivity; import android. OS. bundle; import android. view. menu; import android. view. menuItem; import android. view. view; import android. widget. adapterView; import android. widget. arrayAdapter; import android. widget. spinner; import android. widget. textView; import java. util. arra YList; import java. util. list; public class MainActivity extends ActionBarActivity {private Spinner spinner; private TextView textView; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); spinner = (Spinner) findViewById (R. id. spinner); textView = (TextView) findViewById (R. id. textView); spinner. setPrompt ("select three kingdoms :" ); // The prompt "final List list = new ArrayList (); final List list1 = new ArrayList (); final List list2 = new ArrayList (); list" is displayed in the drop-down box. add ("zhao Yun"); list. add ("Zhuge Liang"); list. add ("Guan Yu"); list. add ("LV Bu"); list1.add ("Zi Long"); list1.add ("Zi Kong Ming"); list1.add ("Zi yun long"); list1.add ("Zi Feng Xian "); list2.add ("Force: 90 \ n intelligence: 70 \ n endurance: 80"); list2.add ("force: 10 \ n intelligence: 100 \ n endurance: 20 "); list2.add ("Force: 95 \ n intelligence: 60 \ n endurance: 80"); list2.add ("Force: 100 \ n intelligence: 50 \ N endurance: 70 "); ArrayAdapter adpter = new ArrayAdapter (this, android. r. layout. simple_spinner_item, list); spinner. setAdapter (adpter); spinner. setOnItemSelectedListener (new AdapterView. onItemSelectedListener () {@ Override public void onItemSelected (AdapterView <?> Parent, View view, int position, long id) {textView. setText ("selected:" + list. get (position) + ": \ t" + list1.get (position); textView. append ("\ n personal information: \ n" + list2.get (position) ;}@ Override public void onNothingSelected (AdapterView <?> Parent) {}}) ;}</span>
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.