国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android下拉列表spinner的實例代碼

2019-12-12 06:18:38
字體:
來源:轉載
供稿:網友

spinner組件有點類型于HTML中的下拉框<Select></select>的樣子,讓用戶每次從下拉框中選取一個,本文為大家分享了Android下拉列表spinner的具體實現代碼,供大家參考,具體內容如下

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[] { "第一項",      "第二項", "第三項" });  //設置下拉樣式  adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);  spinner.setAdapter(adapter); }}

效果圖:

其中主要涉及到兩個xml文件,一個是填充數據時的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" />

以上就是本文的全部內容,希望對大家學習Android軟件編程有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永靖县| 方城县| 叙永县| 新泰市| 九龙坡区| 渝北区| 淄博市| 鸡泽县| 榆中县| 辽中县| 安庆市| 河曲县| 佛学| 手游| 博乐市| 宝兴县| 鹰潭市| 峨山| 韶关市| 延吉市| 馆陶县| 察哈| 泰来县| 牙克石市| 长治县| 宜君县| 临江市| 长岛县| 会同县| 金坛市| 文成县| 盱眙县| 南江县| 神池县| 瑞丽市| 株洲县| 玉溪市| 甘德县| 台中县| 甘德县| 孟连|