Android Studio: Use of the AutoCompleteTextView control and androidstudio Control
If you enter the information we want to enter in the input box, other related prompts will appear. This effect is achieved in Android using AutoCompleteTextView. The AutoCompleteTextView control inherits from the TextView control and has its own properties:
AutoCompleteTextView common attributes |
Android: completionHint |
Set the title of the prompt that appears in the drop-down menu |
Android: completionThreshold |
Set the number of characters that the user must enter to display the prompt. |
Android: dropDownHorizontalOffset |
Horizontal offset between text boxes in the drop-down menu. Align left with text box by default |
Android: dropDownHeight |
Height of the drop-down menu |
Android: dropDownWidth |
Width of the drop-down menu |
Android: singleLine |
Single Row display |
Android: dropDownVerticalOffset |
Vertical offset |
I. Effects:
Ii. Code:
<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: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/activity_vertical_margin" android: paddingBottom = "@ dimen/plugin" tools: context = ". mainActivity "android: orientation =" vertical "> <TextView android: text =" Enter the Search Keyword: "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: textSize = "30dp"/> <AutoCompleteTextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: id = "@ + id/KeyWords" android: textSize = "30dp"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_gravity = "center_horizontal" android: text = "Search" android: textSize = "35dp"/> </LinearLayout>
Package com. example. lhb. autocompletetextview; import android. app. searchableInfo; import android. support. v7.app. actionBarActivity; import android. OS. bundle; import android. view. menu; import android. view. menuItem; import android. widget. arrayAdapter; import android. widget. autoCompleteTextView; public class MainActivity extends ActionBarActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); Search ();} private void Search () {String [] aut = new String [] {"Android", "Android software", "Android Project ", "Android Studio" }; ArrayAdapter <String> adapter = new ArrayAdapter <String> (this, R. layout. abc_simple_dropdown_hint, aut); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById (R. id. keyWords); textView. setAdapter (adapter );}}