How to pop up a suggestion when entering

Source: Internet
Author: User

We can use autocompletetextview to enable the user to pop up the suggestion item when entering.
Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. widget. arrayadapter;
Import Android. widget. autocompletetextview;
Import com. Sec. Android. touchwiz. samples. R;
Public class searchboxsample1xml extends activity {

@ Override

Protected void oncreate (bundle savedinstancestate ){

Super. oncreate (savedinstancestate );



Setcontentview (R. layout. searchboxsample1xml_main );

Arrayadapter <string> adapter = new arrayadapter <string> (this,

R. layout. searchboxsample1xml_dropdown_text, countries );



Autocompletetextview textview = (autocompletetextview) findviewbyid (R. Id. searchfield );

Textview. setadapter (adapter );
}
// Used to pop up when input
Private Static final string [] countries = new string [] {
"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra ",
"Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina ",
"Armenia", "Aruba", "Australia", "Austria", "Azerbaijan ",
"Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium ",
"Belize", "Benin", "Bermuda", "Bhutan", "bolivia ",
"Bosnia and Herzegovina", "Botswana", "Bouvet island", "Brazil", "British Indian Ocean Territory ",
"British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi ",
"Cote d 'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde ",
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China ",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo ",
"Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic ",
"Democratic Republic of the Congo", "Denmark", "djiboti", "Dominica", "Dominican Republic ",
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea ",
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland ",
"Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia ",
"French Southern territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar ",
"Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau ",
"Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary ",
"Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica ",
"Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos ",
"Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg ",
"Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands ",
"Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova ",
"Monaco", "tianlia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia ",
"Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand ",
"Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas ",
"Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru ",
"Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar ",
"Reunion", "Romania", "Russia", "Rwanda", "sqo tome and Principe", "Saint Helena ",
"Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon ",
"Saint Vincent and the Grenadines", "Samoa", "San Marino", "saudi arabia", "Senegal ",
"Seychelles", "sisierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands ",
"Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea ",
"Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden ",
"Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas ",
"The Gambia", "Togo", "Tokelau", "tonga", "Trinidad and Tobago", "Tunisia", "Turkey ",
"Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda ",
"Ukraine", "United Arab Emirates", "United Kingdom ",
"United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan ",
"Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara ",
"Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
};
}
Layout file searchboxsample1xml_main.xml:
<? XML version = "1.0" encoding = "UTF-8"?>

<Linearlayout

Xmlns: Android = "http://schemas.android.com/apk/res/android"

Android: layout_width = "fill_parent"

Android: layout_height = "wrap_content"

Android: Orientation = "vertical">



<! -- Header: search box -->

<Linearlayout

Android: layout_width = "fill_parent"

Android: layout_height = "58dp"

Android: Orientation = "horizontal"

Android: Background = "@ drawable/searchboxsample1xml_header_bg">

<Autocompletetextview
Android: Id = "@ + ID/searchfield"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_vertical"
Android: layout_weight = "1"
Android: drawableleft = "@ drawable/searchboxsample1xml_internet_google"
Android: singleline = "true"
Android: completionthreshold = "1"
Android: popupbackground = "@ drawable/searchboxsample1xml_dropdown_popup_bg"/>
<Button
Android: Id = "@ + ID/searchbtn"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/searchboxsample1xml_search"
Android: layout_gravity = "center_vertical"/>
</Linearlayout>

<! -- Items -->
<Textview
Android: Id = "@ + ID/searchguidetext"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: paddingleft = "6dp"
Android: textcolor = "@ touchwiz: color/tw_color001"
Android: textsize = "18sp"
Android: text = "@ string/searchboxsample1xml_content"/>
</Linearlayout>

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.