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;

    } }

    既然走上了这条路,那么久不能背信弃义,就要一直走下去。即使前面是刀山火海也要闯一闯。至于结果是悲喜,或许只有时间才能给出答案。
  • 相关阅读:
    XMPP Openfire集成windows身份认证
    WIF claimsbased identity
    VMWare Workstation使用总结几则
    把成熟的代码从.NET移植到Mono 【转】
    工作流jBPM使用总结
    C++实现的IO高效的算法TPIE
    XMPP的简介和基本概念
    NoSQL学习路线图 使用 NoSQL 数据库分析大规模数据[转]
    Spring Security 3 网站安全授权
    jBPM 5 的点滴
  • 原文地址:https://www.cnblogs.com/yckv/p/4808894.html
Copyright © 2011-2022 走看看