android下拉菜单 spinner 学习
首先看一下继承关系:
public class
Spinner
extends AbsSpinner
implements DialogInterface.OnClickListener
Class Overview
视图在同一时间只能显示一个子项,用户通过下拉的方式可以选择其中的一种项。该子项在 Spinner来自来Adpater 视图适配器。
首先看一下效果图:
Spinner 控件的使用
一个简单的Spinner使用只需要下面几步:
(1)新建一个工程
(2)在布局文件中插入一下 Spinner 控件
布局如下:
<?xml version="1.0" encoding="utf-8"?>
<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="com.jcdh.jcli.spinner.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Where are you from"
android:id="@+id/textView"
android:textSize="30sp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/> <Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/planets_spinner"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/>
</LinearLayout>
在资源Value/String定义一个数组:
array defined in a stringresource file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
</string-array>
</resources>
spinner 控件可以放在Activiy或Fragment中,通过Adapter得到数据源:
Spinner spinner = (Spinner) findViewById(R.id.spinner); setOnItemSelectedListener(this)
// Create an ArrayAdapter using the string array and a default spinner layoutArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appearsadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinnerspinner.setAdapter(adapter);
例,Activity 处理监听:
public class SpinnerActivity extends Activity implements OnItemSelectedListener {
...
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
}
最后出效果:
Demo 下载 http://download.csdn.net/detail/q610098308/9326759
android下拉菜单 spinner 学习的更多相关文章
- android下拉菜单spinner的使用方法
Spinner控件也是一种列表类型的控件,它的继承关系如下: java.lang.Object ↳ android.view.View ↳ android.view.ViewGrou ...
- Android 下拉菜单 Spinner 赋值
private Spinner m_spiModel = null; //产品型号 m_spiModel = (Spinner) findViewById(R.id.spiModel);//产品型号 ...
- 下拉菜单 Spinner 简单纯字符串版
下拉菜单 Spinner 简单纯字符串版 public class MainActivity extends Activity implements AdapterView.OnItemSelecte ...
- jQuery手写几个常见的滑动下拉菜单 分分秒秒学习JS
一般的企业网站再我们再实际工作中,有些特效,用jQuery来做,显得极其简单,除非一些大的公司,需要封装自己的类. 今天,我们讲解jQuery入门知识,来写几个简单jQuery滑动下拉菜单.感受一下j ...
- Android开发手记(10) 下拉菜单Spinner
1.自定义Spinner 首先,定义Spinner要显示的项目列表/res/values/arrays.xml <?xml version="1.0" encoding=&q ...
- Android:有关下拉菜单导航的学习(供自己参考)
Android:有关==下拉菜单导航==的学习 因为先前的学习都没想着记录自己的学习历程,所以该博客才那么迟才开始写. 内容: ==下拉菜单导航== 学习网站:android Spinner控件详解 ...
- Android零基础入门第46节:下拉框Spinner
原文:Android零基础入门第46节:下拉框Spinner 上一期学习了GridView的使用,你已经掌握了吗?本期一起来学习Spinner的使用. 一.认识Spinner Spinner其实就是一 ...
- android下拉选择框spinner
spinner是什么东西呢?有点像下拉菜单,其实是一个弹出窗口,但是是可以进行进一步操作的弹出窗口.你点击那个三角形的符号,弹出一个窗口,通常是列表,然后进行操作. 它在xml文件中的定义和其它控件没 ...
- Android_(控件)动态添加或删除Spinner下拉菜单
使用ArrayList动态数组的依赖性实现动态增减Spinner下拉菜单选项功能. 设置一个EditText输入框,当用户输入了文字并单击[添加]按钮的同时,就会将输入的值添加Spinner至下拉菜单 ...
随机推荐
- HackerRank "Permutation game"
A typical game theory problem - Recursion + Memorized Searchhttp://justprogrammng.blogspot.com/2012/ ...
- 如何解决WebkitBrowser使用出错“Failed to initialize activation context”
本文转载自:http://www.cnblogs.com/supjia/p/4695671.html 本篇文章主要介绍了"如何解决WebkitBrowser使用出错“Failed to in ...
- 利用MyEclipse自动创建PO类、hbm文件(映射文件)、DAO
原文地址:http://blog.csdn.net/fangzhibin4712/article/details/7179414 前提条件:表sjzdfl 表sjzdxx (使用数据库MySQL) ...
- requestscope.contextpath和<%=request.getContextPath()%>有何区别?(待解答)
问题1:requestscope.contextpath和<%=request.getContextPath()%>有何区别? 问题2:${requestscope.contextpath ...
- 访问public
public(C# 参考) public 关键字是类型和类型成员的访问修饰符. 公共访问是允许的最高访问级别. 对访问公共成员没有限制,如下例所示: class SampleClass { publi ...
- 黄聪:让WordPress主题支持语言本地化(使用poedit软件实现中文翻译功能)
如果你的WordPress主题要提交到WordPress官方主题库,使用者来自世界各地的多种语言,那么,你就要让你的WordPress主题支持语言本地化,方便使用者进行语言翻译和制作语言包. 让Wor ...
- Android: 触屏fling/scroll/drag的区别及其详细过程
Google了一下,终于搞清了touch screen下的几种操作模式(对应的是事件). 对于一个view, 常用的操作有点击(click)和长按(long press)二种.实际上,这些操作类型是A ...
- Scala控制抽象
private def filesHere = (new java.io.File(".")).listFiles() def filesEnding(query: String) ...
- MySQL的时间进位问题
mysql更新到5.6.4 之后 , 新增了一个叫factional seconds的特性 , 可以记录时间的毫秒值. 但是目前的数据库是不记录毫秒值的 , 所以会产生一个java中时间的Millis ...
- JAVA 类中方法参数与返回值
无参无返回值的方法,用public void 方法名,来声明: 有参无返回值的方法,用public void 方法名,来声明: 有参有返回值的方法,用public int 方法名(int i,int ...