Spinner就是下拉框组件,可以自定义下拉布局样式,可以使用ArrayAdapter以及SpinnerAdapter适配

在Adapter中实现SpinnerAdapter,继承BaseAdapter类

private class ListAdapter extends BaseAdapter implements SpinnerAdapter {

        @Override
public int getCount() {
return allLists.size();
} @Override
public Object getItem(int position) {
return allLists.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View view, ViewGroup parent) {
TextView text = new TextView(lexs);
text.setText(allLists.get(position).getName());
return text;
} }

然后它不需要重写所有的像isEmpty(), registerDataObserver()这样的方法,但是可以重写getDropDownView(...)方法.

例子:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 定义了一个Spinner组件,
指定该显示该Spinner组件的数组 -->
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/sanguo"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="sanguo">
<item>魏</item>
<item>蜀</item>
<item>吳</item>
</string-array>
</resources>

最新文章

  1. jquery插件编写模版
  2. 微信小程序入门正确姿势(一)
  3. Jetty使用教程(四:23)—Jetty开发指南
  4. Tomcat-问题解决
  5. node.js Websocket消息推送---GoEasy
  6. 关于c++
  7. Hadoop Pig简介、安装、试用
  8. iOS Node Conflict svn冲突
  9. poj 1182 食物链(关系并查集)
  10. tomcat - 部署Web应用
  11. Oozie时出现Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure?
  12. idea历史版本下载
  13. 关于div包裹img,底下多出3px间隙的问题
  14. ●BZOJ 3561 DZY Loves Math VI
  15. 自定义一个仿Spinner
  16. Action访问Servlet API的三种方法
  17. Python Selenium系列学习
  18. maven跳过测试编译命令
  19. 有关centos7 图形化root用户登录
  20. cglib之Enhancer

热门文章

  1. poj1308 Is It A Tree?(并查集)详解
  2. 关于ligerui 中 grid 表格的扩展搜索功能在远程数据加载时无法使用的解决办法
  3. 有理数类 Java
  4. /etc/sysconfig/目录详解
  5. Mac OS X 配置环境变量
  6. 【失败】制作CentOS镜像
  7. @font-face
  8. 学习python网络数据采集笔记-1、2章
  9. 阿里云主机建立SWAP分区脚本
  10. C#中的委托用法