zoukankan      html  css  js  c++  java
  • Android用户界面UI组件--AdapterView及其子类(五) Spinner和SpinnerAdapter

    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>
    




     


  • 相关阅读:
    http简单demo
    启迪思维:循环链表
    数据表行列转换
    防止短时间内重复提交表单数据js约束
    ASP.NET2.0文件上传以及图片处理
    支付宝倒计时代码
    js 定时刷新页面
    C# 将cookiecontainer写到本地
    用C#生成随机中文汉字验证码的基本原理
    删除指定文件夹里的所有文件
  • 原文地址:https://www.cnblogs.com/krislight1105/p/3748365.html
Copyright © 2011-2022 走看看