Android用户界面UI组件--AdapterView及其子类(五) Spinner和SpinnerAdapter
2024-10-18 23:35:22
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>
最新文章
- jquery插件编写模版
- 微信小程序入门正确姿势(一)
- Jetty使用教程(四:23)—Jetty开发指南
- Tomcat-问题解决
- node.js Websocket消息推送---GoEasy
- 关于c++
- Hadoop Pig简介、安装、试用
- iOS Node Conflict svn冲突
- poj 1182 食物链(关系并查集)
- tomcat - 部署Web应用
- Oozie时出现Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure?
- idea历史版本下载
- 关于div包裹img,底下多出3px间隙的问题
- ●BZOJ 3561 DZY Loves Math VI
- 自定义一个仿Spinner
- Action访问Servlet API的三种方法
- Python Selenium系列学习
- maven跳过测试编译命令
- 有关centos7 图形化root用户登录
- cglib之Enhancer