zoukankan      html  css  js  c++  java
  • Android 可以输入的下拉框

    将AutoCompleteTextView与一个button组合起来,做成一个可以输入,也可以选择的下拉框。

    下面是定义的xml文件,auto_spinner.xml:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     xmlns:tools="http://schemas.android.com/tools"
     4     android:layout_width="fill_parent"
     5     android:layout_height="50dip"
     6     android:background="@android:drawable/edit_text"
     7     android:paddingRight="10dip" 
     8     android:weightSum="4">
     9 
    10     <AutoCompleteTextView
    11         android:id="@+id/repeateMode"
    12         android:layout_width="0dip"
    13         android:layout_height="fill_parent"
    14         android:layout_weight="3"
    15         android:background="@null"
    16         android:cacheColorHint="#00000000"
    17         android:completionThreshold="1"
    18         android:dropDownHorizontalOffset="20dp"
    19         android:ems="10"
    20         android:gravity="center_vertical" >
    21 
    22         <requestFocus />
    23     </AutoCompleteTextView>
    24 
    25     <ImageButton
    26         android:id="@+id/repeateModeBtn"
    27         android:layout_width="0dp"
    28         android:layout_height="fill_parent"
    29         android:layout_weight="1.0"
    30         android:src="@android:drawable/btn_dropdown"
    31         />
    32 
    33 </LinearLayout>

    这是部分代码:

    ……
    
        private void init(Context context) {
            // this.context = context;
            LayoutInflater.from(context).inflate(R.layout.auto_spinner, this);
    
            adapter = new ArrayAdapter<String>(context,
                    android.R.layout.simple_dropdown_item_1line, list);
    
            text = (AutoCompleteTextView) this.findViewById(R.id.repeateMode);
            text.setAdapter(adapter);
    
            button = (ImageButton) this.findViewById(R.id.repeateModeBtn);
            button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // 显示下拉框
                    text.showDropDown();
                }
            });
        }

    这样基本几可以了。

  • 相关阅读:
    svn hooks post-commit钩子自动部署
    curl post数据
    php 操作提示框
    php分页类 可直接调用
    微信web端生成支付二维码
    php 数据库类
    虚拟机中的CentOS 7设置固定IP连接最理想的配置
    多并发时支付如何保持账户余额的一致性?
    Spring核心机制:依赖注入
    .net 系列:并发编程之一【并发编程的初步理论】
  • 原文地址:https://www.cnblogs.com/chenlong-50954265/p/3806197.html
Copyright © 2011-2022 走看看