Android 11th Lesson--autocompletetextview

Source: Internet
Author: User

。。。 Baidu on the search for such a paragraph. Understand the purpose of the three parameters of the Arrayadapter

1. This small example is to display an array, we use Arrayadapter, array adapter, data type <> is string type, data type can also be other including object type

2. arrayadapter<string> arrayadapter = new Arrayadapter<string> (Arraylistdemo.this, Android. R.layout.simple_list_item_1,adapterdata);

This code is to create an array adapter code, there are three parameters, the first parameter is the context, is the current activity, the second parameter is the Android SDK in its own built-in layout, it has only one textview, This parameter indicates that the layout of each piece of data in our array is this view, that is, each piece of data is displayed on the view, and the third parameter is the data we want to display. The ListView iterates through each of the data in the Adapterdata according to these three parameters, reads one, displays the layout corresponding to the second parameter, thus forming the ListView we see.

Adapterview function
A adapter object serves as a bridge between the Adapterview and the view underlying data, providing access to the dataitems, and is responsible for rendering to the corresponding view for each data.

Seems to understand the adapter is to do what use ... The feeling is that the data in the array or list is converted into a view ... This is easy to understand ...

The following code: is to automatically complete the text box

<LinearLayoutxmlns: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"><!--defines an AutoComplete text box, specifying that a character is entered to prompt -<AutocompletetextviewAndroid:id= "@+id/auto"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:completionhint= "Please select the book you Like"Android:dropdownhorizontaloffset= "10SP"Android:completionthreshold= "1"        /><!--Define a Multiautocompletetextview -<MultiautocompletetextviewAndroid:id= "@+id/mauto"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:completionthreshold= "1"    /></LinearLayout>
 PackageCom.example.autocompletetv;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.AutoCompleteTextView;ImportAndroid.widget.MultiAutoCompleteTextView; Public classMainactivityextendsActivity {Autocompletetextview ACTV;    Multiautocompletetextview Mauto; //defines a character array as the hint textString[] Books=Newstring[]{"Java Handouts",            "Ajax Handouts",            "XML Handouts",            "Android Handout"    }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //creates a arrayadapter, encapsulates an arrayArrayadapter<string> aa=NewArrayadapter<string> ( This, Android.        R.layout.simple_dropdown_item_1line, books); ACTV=(Autocompletetextview) Findviewbyid (R.id.auto);        Actv.setadapter (AA); Mauto=(Multiautocompletetextview) Findviewbyid (R.id.mauto);        Mauto.setadapter (AA); //set the delimiter for MultiautocompletetextviewMauto.settokenizer (NewMultiautocompletetextview.commatokenizer ()); }    }

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.