Previous: http://www.bkjia.com/kf/201201/115826.html
In Android, AutoCompleteTextView can automatically complete text input boxes, which is similar to Ajax in Web pages. When using this function, you must specify an adapter to set the complete text.
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<! -- Define an Automatic completion text box, specify a character to input and prompt -->
<! -- Android: dropDownHorizontalOffse: sets the horizontal offset of the drop-down list -->
<AutoCompleteTextView
Android: id = "@ + id/auto"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: completionHint = "Please select your favorite song"
Android: dropDownHorizontalOffset = "20dp"
Android: completionThreshold = "1"/> <! -- Specify the number of words to be input and a response prompt -->
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<! -- Define an Automatic completion text box, specify a character to input and prompt -->
<! -- Android: dropDownHorizontalOffse: sets the horizontal offset of the drop-down list -->
<AutoCompleteTextView
Android: id = "@ + id/auto"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: completionHint = "Please select your favorite song"
Android: dropDownHorizontalOffset = "20dp"
Android: completionThreshold = "1"/> <! -- Specify the number of words to be input and a response prompt -->
</LinearLayout>
Public class AutoCompleteTextViewTest extends Activity
{
// Define a string array as the prompt text
String [] books = new String [] {
"Sun Yanzi-hey jude ",
"Sun Yanzi-the moment ",
"Sun Yanzi-tonight I feel close to you ",
"Sun Yanzi-leave me alone"
};
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Create an ArrayAdapter and encapsulate the Array
ArrayAdapter <String> aa = new ArrayAdapter <String> (
This,
Android. R. layout. simple_dropdown_item_1line,
Books );
AutoCompleteTextView actv = (AutoCompleteTextView)
FindViewById (R. id. auto );
// Set the Adapter
Actv. setAdapter (aa );
}
}
Public class AutoCompleteTextViewTest extends Activity
{
// Define a string array as the prompt text
String [] books = new String [] {
"Sun Yanzi-hey jude ",
"Sun Yanzi-the moment ",
"Sun Yanzi-tonight I feel close to you ",
"Sun Yanzi-leave me alone"
};
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Create an ArrayAdapter and encapsulate the Array
ArrayAdapter <String> aa = new ArrayAdapter <String> (
This,
Android. R. layout. simple_dropdown_item_1line,
Books );
AutoCompleteTextView actv = (AutoCompleteTextView)
FindViewById (R. id. auto );
// Set the Adapter
Actv. setAdapter (aa );
}
}
From snoopy's column