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