Android Drop-down List Spinner Instance code _android

Source: Internet
Author: User

The Spinner component is somewhat typed into the dropdown box in HTML <Select></select>, letting the user choose one from the Drop-down box at a time, This article for everyone to share the Android Drop-down list spinner specific implementation code, for your reference, the specific contents are as follows

Mian.xml

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"
 xmlns:tools= "http:// Schemas.android.com/tools "
 android:layout_width=" match_parent "
 android:layout_height=" Match_parent "
 android:orientation= "vertical"
 tools:context= ". Main ">

 <spinner
  android:id=" @+id/spinner "
  android:layout_width=" 300sp "
  android:layout_ height= "50SP"
  android:layout_gravity= "Center_horizontal"/>

</LinearLayout>

Main.java

Package com.app.main;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.ArrayAdapter;
Import Android.widget.Spinner;

public class Main extends activity {

 Spinner Spinner = null;

 @Override
 protected void onCreate (Bundle savedinstancestate) {
  super.oncreate (savedinstancestate);
  Setcontentview (r.layout.main);

  Spinner = (spinner) This.findviewbyid (R.id.spinner);
  Arrayadapter adapter = new Arrayadapter (this,
    Android. R.layout.simple_spinner_item, new string[] {"First item",
      "second item", "Third Item"});

  Sets the Drop-down style
  Adapter.setdropdownviewresource (Android. R.layout.simple_dropdown_item_1line);
  Spinner.setadapter (adapter);
 }



Effect Chart:

The main concerns are two XML files, one is the Simple_spinner_item.xml and Drop-down style when populating data simple_dropdown_item_1line

Simple_spinner_item.xml:

<textview xmlns:android= "http://schemas.android.com/apk/res/android" 
 android:id= "@android: Id/text1"
 Style= "Android:attr/spinneritemstyle"
 android:singleline= "true"
 android:layout_width= "Match_parent"
 android:layout_height= "wrap_content"
 android:ellipsize= "marquee"
 android:textalignment= "Inherit"/ >

Simple_dropdown_item_1line.xml:

<textview xmlns:android= "http://schemas.android.com/apk/res/android" 
 android:id= "@android: Id/text1"
 style= "Android:attr/dropdownitemstyle"
 android:textappearance= "? android:attr/ Textappearancelargepopupmenu "
 android:singleline=" true "
 android:layout_width=" Match_parent
 " android:layout_height= "Android:attr/listpreferreditemheight"
 android:ellipsize= "marquee"/>

The above is the entire content of this article, I hope to learn about Android software programming help, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.