Home » Android » Android study notes the Spinner drop-down box func...

Android study notes the Spinner drop-down box function, use


A similar controls drop-down list, select the appropriate option from the user in
The data in the Spinner need to use Adapter (adapter) filled.


layout file
Android:layout_width= "match_parent"
Android:layout_height= "wrap_content"
Android:id= "@+id/textView"
Android:layout_width= "match_parent"
Android:layout_height= "wrap_content"

class file MainActivity.java:

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.ArrayList;
Import java.util.List;
Public class MainActivity extends {ActionBarActivity
Private Spinner spinner;
Private TextView textView;
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 characters:"); / / the drop-down box to prompt
Final List list = new (ArrayList);
Final List LIST1 = new (ArrayList);
Final List List2 = new (ArrayList);
List.add ("Zhao Yun");
List.add ("Zhu Geliang");
List.add ("Guan");
List.add ("Lv Bu");
List1.add ("dragon");
List1.add ("Kongming");
List1.add ("cloud");
List1.add ("Fengxian");
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 ArrayAdapter (this = new,
Android.R.layout.simple_spinner_item, list);
Spinner.setAdapter (adpter);
Spinner.setOnItemSelectedListener (new (AdapterView.OnItemSelectedListener) {
Public void onItemSelected (AdapterView< > parent, View view?,
Int position, long ID) {
TextView.setText ("select" +list.get (position) + "t" +list1.get (position));
TextView.append ("n personal information: n +list2.get (position));
Public void onNothingSelected (AdapterView< parent {? >)

copyright statement: This article for bloggers, original articles, bloggers may not be reproduced without permission of.