亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android下拉列表spinner的實(shí)例代碼

 更新時(shí)間:2016年05月27日 16:39:45   作者:summerpxy  
這篇文章主要為大家詳細(xì)介紹了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軟件編程有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 基于Android10渲染Surface的創(chuàng)建過程

    基于Android10渲染Surface的創(chuàng)建過程

    這篇文章主要介紹了基于Android10渲染Surface的創(chuàng)建過程,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-08-08
  • 如何為RecyclerView添加Header和Footer

    如何為RecyclerView添加Header和Footer

    這篇文章主要為大家詳細(xì)介紹了如何為RecyclerView添加Header和Footer,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Android 實(shí)現(xiàn)單線程輪循機(jī)制批量下載圖片

    Android 實(shí)現(xiàn)單線程輪循機(jī)制批量下載圖片

    這篇文章主要介紹了Android 單線程輪循機(jī)制批量下載圖片的相關(guān)資料,這里對實(shí)現(xiàn)步驟做了詳細(xì)介紹,需要的朋友可以參考下
    2017-07-07
  • Android開發(fā)之注冊登錄方法示例

    Android開發(fā)之注冊登錄方法示例

    這篇文章主要介紹了Android開發(fā)的注冊登錄方法,是針對Android程序設(shè)計(jì)中版本兼容性的進(jìn)一步完善,需要的朋友可以參考下
    2014-08-08
  • Android氣泡效果實(shí)現(xiàn)方法

    Android氣泡效果實(shí)現(xiàn)方法

    這篇文章主要介紹了Android氣泡效果實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了Android實(shí)現(xiàn)氣泡效果的頁面布局及功能代碼,涉及RelativeLayout布局,TextView控件及對話框Dialog相關(guān)使用技巧,需要的朋友可以參考下
    2016-01-01
  • Android API開發(fā)之SMS短信服務(wù)處理和獲取聯(lián)系人的方法

    Android 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 8.0的緩存大小和緩存清理接口方法

    Android 8.0的緩存大小和緩存清理接口方法

    今天小編就為大家分享一篇Android 8.0的緩存大小和緩存清理接口方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • 詳解Android如何實(shí)現(xiàn)好的彈層體驗(yàn)效果

    詳解Android如何實(shí)現(xiàn)好的彈層體驗(yàn)效果

    當(dāng)前?App?的設(shè)計(jì)趨勢越來越希望給用戶沉浸式體驗(yàn),這種設(shè)計(jì)會(huì)讓用戶盡量停留在當(dāng)前的界面,而不需要太多的跳轉(zhuǎn),這就需要引入彈層。本篇我們就來講講彈層這塊需要注意哪些用戶體驗(yàn)
    2022-11-11
  • Android中TextView自動(dòng)識(shí)別url且實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)

    Android中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-03
  • Android開啟ADB網(wǎng)絡(luò)調(diào)試方法

    Android開啟ADB網(wǎng)絡(luò)調(diào)試方法

    今天小編就為大家分享一篇Android開啟ADB網(wǎng)絡(luò)調(diào)試方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08

最新評論