Android列表控件Spinner簡單用法示例
本文實(shí)例講述了Android列表控件Spinner簡單用法。分享給大家供大家參考,具體如下:
Android的Spinner控件用來顯示列表項(xiàng),類似于一組單選框RadioButton。這里介紹一下其簡單用法:
xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinaerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Spinner
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:entries="@strings/books"
android:prompt="@string/tip"
/>
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/tip"
/>
</LinaerLayout>
java代碼部分:
package com.example.test06;
import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class MainActivity extends Activity {
Spinner spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner=(Spinner)findViewById(R.id.spinner);
String[] arr={"孫悟空","豬八戒","唐僧"};
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,arr);
spinner.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
FragmentTabHost FrameLayout實(shí)現(xiàn)底部導(dǎo)航欄
這篇文章主要為大家詳細(xì)介紹了FragmentTabHost和FrameLayout實(shí)現(xiàn)底部導(dǎo)航欄,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03
解決Android studio中關(guān)于模擬器的/data目錄不能顯示的問題
這篇文章主要介紹了解決Android studio中關(guān)于模擬器的/data目錄不能顯示的問題,主要原因還是我們權(quán)限不夠,當(dāng)前的用戶沒有權(quán)限訪問data目錄。具體解決方法大家跟隨腳本之家小編一起看看吧2018-06-06
Android 實(shí)現(xiàn)伸縮布局效果示例代碼
這篇文章主要介紹了Android 實(shí)現(xiàn)伸縮布局效果的示例代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-01-01
Android實(shí)現(xiàn)可播放GIF動畫的ImageView
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)可播放GIF動畫的ImageView,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
Android Google AutoService框架使用詳解
AutoService是Google開發(fā)一個自動生成SPI清單文件的框架??催^一些基于APT的三方框架源碼的讀者應(yīng)該有所了解。比如Arouter、EventBus等等2022-11-11
Android中懸浮窗口的實(shí)現(xiàn)原理實(shí)例分析
這篇文章主要介紹了Android中懸浮窗口的實(shí)現(xiàn)原理,以實(shí)例形式較為詳細(xì)的分析了Android懸浮窗口的原理與具體實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10
Android通過ImageView設(shè)置手指滑動控件縮放
這篇文章主要介紹了Android通過ImageView設(shè)置手指滑動控件縮放效果,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-12-12

