The essay tips feature is a good way to help users with convenient information input, and in Android also provides similar features, The implementation of this function relies on the Android.widget.AutoCompleteTextView class, and the inheritance structure of this class is as follows:Java.lang.Object ? Android.view.View ? Android.widget.TextView ? Android.widget.EditText ? Android.widget.AutoCompleteTextView
No. |
Method |
Type |
Describe |
1 |
public void Clearlistselection () |
Ordinary |
Clears all drop-down list items |
2 |
Public ListAdapter Getadapter () |
Ordinary |
Get Data Set |
3 |
public void Setadapter (T adapter) |
Ordinary |
Set up datasets |
4 |
public void Setonclicklistener (View.onclicklistener listener) |
Ordinary |
Set Click events |
5 |
Public void Setonitemclicklistener (adapterview.onitemclicklistener L) |
Ordinary |
Set the Click event on the option |
6 |
Public void Setonitemselectedlistener (adapterview.onitemselectedlistener L) |
Ordinary |
Click event when the option is selected |
Here is a demo to explain this component
XML file
<span style= "FONT-SIZE:18PX;" ><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 " 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=". Mainactivity "> <autocompletetextview android:id=" @+id/text " android:layout_width=" Match_ Parent " android:layout_height=" wrap_content "> </autocompletetextview></relativelayout ></span>
Java files
<span style= "FONT-SIZE:18PX;" >package Com.example.autocompleteterxtview;import Android.app.activity;import Android.os.Bundle;import Android.view.view;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;import Android.widget.arrayadapter;import Android.widget.autocompletetextview;import Android.widget.Toast;public Class Mainactivity extends Activity {private Autocompletetextview autocompletetextview=null;// Create Autocompletetextview object private static final String data[] = {"Wind snow is not young", "Wind Flies", "Wind Fly Rain", "Wind Fly Rainstorm", "Wind Come Ah"};//set dataset @overridepr otected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Super.setcontentview ( R.layout.activity_main); Autocompletetextview = (Autocompletetextview) This.findviewbyid (R.id.text);//instantiation of objects// Create a adapter storage data setting display, followed by a detailed explanation of the ListView component Arrayadapter<string> adapter = new Arrayadapter<string> ( This, Android. R.layout.simple_dropdown_item_1line,data); This.autoCompleteTextView.setAdapter (ADAPter);//Click the settings for the event. will be explained in the future, here is mainly to test the method of the component This.autoCompleteTextView.setOnItemClickListener (new Onitemclicklistener () {@ overridepublic void Onitemclick (adapterview<?> parent, View view,int position, long ID) {//TODO auto-generated Meth Od stubtoast.maketext (Mainactivity.this, "you selected" +data[position], 2). Show ();//Hint component, prompt message});}} </span>
button Component Effects
the set of the component is relatively simple answer, you can try other methods
next section forecast, Toast Toast tip component