zoukankan      html  css  js  c++  java
  • AutoCompleteTextView

     

     

    activity_main.xml文件

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

        android:paddingBottom="@dimen/activity_vertical_margin"

        android:paddingLeft="@dimen/activity_horizontal_margin"

        android:paddingRight="@dimen/activity_horizontal_margin"

        android:paddingTop="@dimen/activity_vertical_margin"

        tools:context="com.example.autocompletetextviewdemo.MainActivity" >

     

        <AutoCompleteTextView

            android:id="@+id/autoCompleteTextView1"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:hint="请输入要搜索的关键字"

            android:completionThreshold="2" >

     

            <requestFocus />

        </AutoCompleteTextView>

     

    </LinearLayout>

    MainActivity.java

    package com.example.autocompletetextviewdemo;

     

    import android.support.v7.app.ActionBarActivity;

    import android.os.Bundle;

    import android.view.Menu;

    import android.view.MenuItem;

    import android.widget.ArrayAdapter;

    import android.widget.AutoCompleteTextView;

     

    public class MainActivity extends ActionBarActivity {

    //声明控件

    AutoCompleteTextView actv;

    String[] str={"beijing","beijing1","beijing2","nanjing","yanjing","yantai","nanguo"};

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    //初始化控件

    actv=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);

    //需要一个适配器

    ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, str);

    //将适配器与控件绑定

    actv.setAdapter(adapter);

    }

     

    }

     

  • 相关阅读:
    基于 Eclipse 平台的代码生成技术
    mshta命令用法示例(在dos命令弹出消息框)
    opengl绘制正弦曲线
    决策树学习过程中的额外收获---三叉树建立
    C++链表
    java web工程之Hibernate
    Hibernate配置文件学习心得
    TinyMCE在线编辑器使用方法初探
    待修改
    选择问题
  • 原文地址:https://www.cnblogs.com/cn-chy-com/p/7928368.html
Copyright © 2011-2022 走看看