Android下拉列表spinner的實(shí)例代碼
spinner組件有點(diǎn)類型于HTML中的下拉框<Select></select>的樣子,讓用戶每次從下拉框中選取一個(gè),本文為大家分享了Android下拉列表spinner的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
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[] { "第一項(xiàng)", "第二項(xiàng)", "第三項(xiàng)" }); //設(shè)置下拉樣式 adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); spinner.setAdapter(adapter); } }
效果圖:
其中主要涉及到兩個(gè)xml文件,一個(gè)是填充數(shù)據(jù)時(shí)的simple_spinner_item.xml和下拉樣式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" />
以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)Android軟件編程有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框 下拉列表spinner的實(shí)例代碼
- Android UI組件Spinner下拉列表詳解
- Android下拉列表選項(xiàng)框及指示箭頭動(dòng)畫
- Android自定義Spinner下拉列表(使用ArrayAdapter和自定義Adapter實(shí)現(xiàn))
- Android控件Spinner實(shí)現(xiàn)下拉列表及監(jiān)聽功能
- Android仿微信實(shí)現(xiàn)下拉列表
- Android自定義單選多選下拉列表的實(shí)例代碼
- Android仿美團(tuán)淘寶實(shí)現(xiàn)多級(jí)下拉列表菜單功能
- Android使用Spinner控件實(shí)現(xiàn)下拉列表的案例
- Android Studio實(shí)現(xiàn)下拉列表效果
相關(guān)文章
基于Android10渲染Surface的創(chuàng)建過程
這篇文章主要介紹了基于Android10渲染Surface的創(chuàng)建過程,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08如何為RecyclerView添加Header和Footer
這篇文章主要為大家詳細(xì)介紹了如何為RecyclerView添加Header和Footer,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12Android 實(shí)現(xiàn)單線程輪循機(jī)制批量下載圖片
這篇文章主要介紹了Android 單線程輪循機(jī)制批量下載圖片的相關(guān)資料,這里對實(shí)現(xiàn)步驟做了詳細(xì)介紹,需要的朋友可以參考下2017-07-07Android API開發(fā)之SMS短信服務(wù)處理和獲取聯(lián)系人的方法
這篇文章主要介紹了Android API開發(fā)之SMS短信服務(wù)處理和獲取聯(lián)系人的方法,結(jié)合實(shí)例形式分析了Android API實(shí)現(xiàn)SMS短信發(fā)送及獲取聯(lián)系人的相關(guān)操作步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-08-08詳解Android如何實(shí)現(xiàn)好的彈層體驗(yàn)效果
當(dāng)前?App?的設(shè)計(jì)趨勢越來越希望給用戶沉浸式體驗(yàn),這種設(shè)計(jì)會(huì)讓用戶盡量停留在當(dāng)前的界面,而不需要太多的跳轉(zhuǎn),這就需要引入彈層。本篇我們就來講講彈層這塊需要注意哪些用戶體驗(yàn)2022-11-11Android中TextView自動(dòng)識(shí)別url且實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)
這篇文章主要介紹了關(guān)于Android中TextView自動(dòng)識(shí)別url且實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)的相關(guān)資料,文中給出了詳細(xì)的示例代碼,對大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。2017-03-03Android開啟ADB網(wǎng)絡(luò)調(diào)試方法
今天小編就為大家分享一篇Android開啟ADB網(wǎng)絡(luò)調(diào)試方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08