Created
October 11, 2013 20:39
-
-
Save h4ck4life/6941661 to your computer and use it in GitHub Desktop.
Android AutoCompleteTextView example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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="fill_parent" > | |
<TextView | |
android:id="@+id/search_item" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:padding="10dp" | |
android:textColor="#000" | |
android:textSize="16sp" > | |
</TextView> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String[] PRODUCTS = new String[] { "Afghanistan", " Albania", " Algeria", " American Samoa", " Andorra", " Angola", " Anguilla", " Antigua and Barbuda", " Argentina", " Armenia", " Aruba", " Australia", " Austria", " Azerbaijan", " Bahamas", " The", " Bahrain", " Bangladesh", " Barbados", " Belarus", " Belgium", " Belize", " Benin", " Bermuda", " Bhutan", " Bolivia", " Bosnia", " Botswana", " Bougainville", " Brazil", " British Indian Ocean", " British Virgin Islands", " Brunei", " Bulgaria", " Burkina Faso", " Burundi", " Cambodia", " Cameroon", " Canada", " Cape Verde Islands", " Cayman Islands", " Central African Republic", " Chad", " Chile", " China", " Hong Kong", " China", " Macau", " China", " People’s Republic", " China", " Taiwan", " Colombia", " Comoros", " Congo", " Democratic Republic of", " Congo", " Republic of", " Cook Islands", " Costa Rica", " Cote d’Ivoire", " Croatia", " Cuba", " Cyprus", " Czech Republic", " Denmark", " Djibouti", " Dominica", " Dominican Republic", " Ecuador", " Egypt", " El Salvador", " Equatorial Guinea", " Eritrea", " Estonia", " Ethiopia", " Faeroe Islands", " Falkland Islands", " Federated States of Micronesia", " Fiji", " Finland", " France", " French Guiana", " French Polynesia", " Gabon", " Gambia", " The", " Georgia", " Germany", " Ghana", " Gibraltar", " Greece", " Greenland", " Grenada", " Guadeloupe", " Guam", " Guatemala", " Guinea", " Guinea-Bissau", " Guyana", " Haiti", " Holy See (Vatican City State)", " Honduras", " Hungary", " Iceland", " India", " Indonesia", " Iran", " Iraq", " Ireland", " Israel", " Italy", " Jamaica", " Japan", " Jordan", " Kazakhstan", " Kenya", " Kiribati", " Korea", " Democratic People’s Rep", " Korea", " Republic of", " Kosovo", " Kuwait", " Kyrgyzstan", " Laos", " Latvia", " Lebanon", " Lesotho", " Liberia", " Libya", " Liechtenstein", " Lithuania", " Luxembourg", " Macedonia", " Madagascar", " Malawi", " Malaysia", " Maldives", " Mali", " Malta", " Martinique", " Mauritania", " Mauritius", " Mayotte", " Mexico", " Moldova", " Monaco", " Mongolia", " Montenegro", " Montserrat", " Morocco Mozambique", " Myanmar", " Namibia", " Nauru", " Nepal", " Netherlands", " Netherlands Antilles", " New Caledonia", " New Zealand", " Nicaragua", " Niger", " Nigeria", " Norway", " Oman", " Pakistan", " Palestine", " Panama", " Papua New Guinea", " Paraguay", " Peru", " Philippines", " Poland", " Portugal", " Puerto Rico", " Qatar", " Réunion", " Romania", " Russia", " Rwanda", " Saint Barthelemy", " Saint Helena", " Saint Kitts & Nevis", " Saint Lucia", " Saint Martin", " Saint Pierre & Miquelon", " Saint Vincent", " Samoa", " San Marino", " Sao Tomé & Principe", " Saudi Arabia", " Senegal", " Serbia", " Seychelles", " Sierra Leone", " Singapore", " Slovakia", " Slovenia", " Solomon Islands", " Somalia", " South Africa", " Spain", " Sri Lanka", " Sudan", " Suriname", " Swaziland", " Sweden", " Switzerland", " Syria", " Tajikistan", " Tanzania", " Thailand", " Timor Leste", " Togo", " Tokelau Islands", " Tonga", " Trinidad & Tobago", " Tunisia", " Turkey", " Turkmenistan", " Turks & Caicos Islands", " Tuvalu", " Uganda", " Ukraine", " United Arab Emirates", " United Kingdom of GB & NI", " United States of America", " Uruguay", " US Virgin Islands", " Uzbekistan", " Vanuatu", " Venezuela", " Vietnam", " Wallis & Futuna Islands", " Yemen", " Zambia", " Zimbabwe" }; | |
final AutoCompleteTextView textView = (AutoCompleteTextView) rootView | |
.findViewById(R.id.autocompletesearch); | |
ArrayAdapter<String> adapter = new ArrayAdapter<String>( | |
getActivity(), | |
R.layout.list_item_search_autocomplete, | |
R.id.search_item, | |
PRODUCTS); | |
textView.setAdapter(adapter); | |
textView.setOnItemClickListener(new OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> view, View arg1, int arg2, long arg3) { | |
// TODO Auto-generated method stub | |
Toast.makeText(getActivity().getApplicationContext(), textView.getText(), Toast.LENGTH_SHORT).show(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment