Android: AutoCompleteTextView and android Regular Expression matching

Source: Internet
Author: User

Android: AutoCompleteTextView and android Regular Expression matching

 

AutoCompleteTextView is an automatic match character. When we enter the first few words of a word or a paragraph, it will automatically match the following content for you:

The following code is used:

MainActivit:

Package com. example. autocompletetextview; import java. util. arrayList; import java. util. list; import android. support. v7.app. actionBarActivity; import android. OS. bundle; import android. widget. arrayAdapter; import android. widget. autoCompleteTextView; public class MainActivity extends ActionBarActivity {AutoCompleteTextView autoCompleteTextView = null; AutoCompleteTextView auto2 = null; private static final String [] COUNTRIES = {"china", "canada", "Belgium ", "France", "Italy", "Germany", "Spain"}; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); autoCompleteTextView = (AutoCompleteTextView) findViewById (R. id. auto1); auto2 = (AutoCompleteTextView) findViewById (R. id. auto2);/* in static mode, the automatically matched value has been set in advance * The first parameter indicates the current context * The second parameter is the displayed matching layout, the existing layout of Android is used here. * The third parameter is an array storing automatically matched values */ArrayAdapter <String> adapter = new ArrayAdapter <String> (this, android. r. layout. simple_dropdown_item_1line, COUNTRIES); autoCompleteTextView. setAdapter (adapter);/** dynamic mode. The automatically matched value is determined by list */List <String> list = new ArrayList <String> (); list. add ("test aadd"); list. add ("test object"); list. add ("test home"); ArrayAdapter <String> adapter2 = new ArrayAdapter <String> (this, R. layout. simple_1, list); auto2.setAdapter (adapter2 );}}

Main_activity:

<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: orientation = "vertical"> <TextView android: layout_width = "match_parent" android: layout_height = "wrap_content" android: text = "static implementation:"/> <AutoCompleteTextView android: id = "@ + id/auto1" android: layout_width = "match_parent" android: layout_height = "wrap_content"/> <TextView android: layout_width = "match_parent" android: layout_height = "wrap_content" android: text = ":"/> <AutoCompleteTextView android: id = "@ + id/auto2" android: layout_width = "match_parent" android: layout_height = "wrap_content"/> </LinearLayout>

Simple_1.xml:

<?xml version="1.0" encoding="utf-8"?>    <TextView         android:id="@+id/textview"        android:layout_width="match_parent"        android:layout_height="wrap_content"         android:textSize="20dp"        xmlns:android="http://schemas.android.com/apk/res/android"/>

 

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.