Read Android from entry to entry (12)-Automatically complete text box

Source: Internet
Author: User

Read Android from entry to entry (12)-Automatically complete text box
AutoCompleteTextView)

Java. lang. Object;
Android. view. View;
Android. view. TextView;
Android. widget. EditText;
Android. widget. AutoCompleteTextView;
MultiAutoCompleteTextView;

AutoCompleteTextView Class Method

AutoCompleteTextView example

Complete: http://download.csdn.net/detail/sweetloveft/9408072

The following program mainly describes how to use AutoCompleteTextView. This control cannot specify android: entries in the layout file. It does not check whether there are other specified methods. Therefore, it is decided to use code loading! In layout .

1. MainActivity. java

 

package com.sweetlover.activity;import com.sweetlover.autocompletetextviewdemo.R;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;public class MainActivity extends Activity {private static final String[] phoneNumber = new String[]{"111234", "133126", "303404", "796863"};private AutoCompleteTextView autoTextView = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ArrayAdapter
 
   adapter = new ArrayAdapter
  
   (this,android.R.layout.simple_dropdown_item_1line, phoneNumber);autoTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);autoTextView.setAdapter(adapter);}}
  
 
2. activity_main.xml
<!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--><linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="30dp" android:orientation="vertical">    <autocompletetextview android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:hint="@string/note" android:ems="20">        <requestfocus>        <!--{cke_protected}{C}%3C!%2D%2D%20http%3A%2F%2Fzhangkun716717-126-com.iteye.com%2Fblog%2F802201%20%2D%2D%3E-->    </requestfocus></autocompletetextview></linearlayout>
3. string. xml
<Resources> <string name = "app_name"> AutoCompleteTextViewDemo </string> <string name = "note"> enter the phone number </string> </resources>
4. AndroidManifest. xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sweetlover.autocompletetextviewdemo" android:versioncode="1" android:versionname="1.0">    <uses-sdk android:minsdkversion="8" android:targetsdkversion="19">    <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">        <activity android:name="com.sweetlover.activity.MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN">                <category android:name="android.intent.category.LAUNCHER">            </category></action></intent-filter>        </activity>    </application></uses-sdk></manifest>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.