Android Development Learning notes (9) Android Application Interface Programming autocompletetextview Learning

Source: Internet
Author: User

Autocompletetextview is an automatic text box inherited from edittext.

Important attributes:

Android: completionhint

Android: completionthreshold

The test application contains only one simple text box. After a character is entered, the matching string is displayed in the drop-down menu.

When using autocompletetextview, you must match an adapter to provide the content displayed in the drop-down menu.

Final effect:

Program code:

Layout file:

<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/txt"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:hint="Type some characters"        android:completionThreshold="1"        android:popupBackground="#cccccc" /></RelativeLayout>

Java file:

package com.xujin.autocompletetextviewtest;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;public class MainActivity extends Activity {String [] chars = new String[]{"Andy", "Angel Girl","Andrea", "Air Traffic","Akon",  "Alan Jackson", "Alison Krauss", "Alizee",};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, chars);AutoCompleteTextView ac =(AutoCompleteTextView)findViewById(R.id.txt);ac.setAdapter(aa);}}

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.