zoukankan      html  css  js  c++  java
  • Android AoutCompleteTextView控件的使用

    AoutCompleteTextView

    功能:1>动态匹配输入的内容,如百度搜索引擎当输入文本时可以根据内容显示匹配的热门信息

    2>独特属性:android:completionThreshold="2"<!--设置输入多少字符时自动匹配 -->

    自动匹配的layout布局

    <RelativeLayout 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"

    tools:context=".MainActivity" >

    <AutoCompleteTextView 
    android:id="@+id/autocompletetextview"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:hint="请输入需要查询的关键字"

    android:completionThreshold="2"  />

    自动匹配的class文件

    package cn.androidstudy.demo;

    import android.os.Bundle;

    import android.app.Activity;

    import android.view.Menu;

    import android.widget.ArrayAdapter;

    import android.widget.AutoCompleteTextView;

    public class MainActivity extends Activity {

    private AutoCompleteTextView acTextView;

    private String[] res = { "shanghai", "beijing", "tianjing", "sichuan", "yibin", "sichuanjianzhuzhiyijishuxueyuan" };

    @Override protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    /** *  * 1.初始化控件:acTextView=(AutoCompleteTextView) * findViewByld(R.id.autocompletetextview) 

    * 2.需要一个适配器:ArrayAdapter * <String> adapeter = new ArrayAdapter<String>(this, * android.R.layout.simple_expandable_list_item_1, res);

    * 3.初始化数据源---这数据源自动去匹配文本框的内容private String[] res = { "shanghai", "beijing", * "tianjing", "sichuan", "yibin", "sichuanjianzhuzhiyijishuxueyuan" };

    * 4.将adapeter和AoutCompleteTextView绑定:acTextView.setAdapter(adapeter); *  */

    acTextView = (AutoCompleteTextView) findViewById(R.id.autocompletetextview);

    ArrayAdapter<String> adapeter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, res);

    acTextView.setAdapter(adapeter); }

    @Override public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.

    getMenuInflater().inflate(R.menu.main, menu); return true;

    } }

    既然走上了这条路,那么久不能背信弃义,就要一直走下去。即使前面是刀山火海也要闯一闯。至于结果是悲喜,或许只有时间才能给出答案。
  • 相关阅读:
    Python3 从零单排10_xml&configparser
    Python3 从零单排9_json&pickle&shelve
    Python3 从零单排7_模块&os&sys
    Python3 从零单排6_装饰器&生成器&迭代器
    Python3 从零单排5_内置函数
    python3 从零单排4_函数进阶
    Python3 从零单排2_文件读写&集合
    查看innodb表空间
    如何从innodb的数据字典里恢复表结构
    innodb double write buffer
  • 原文地址:https://www.cnblogs.com/yckv/p/4808894.html
Copyright © 2011-2022 走看看