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.