Skip to content

Instantly share code, notes, and snippets.

@gauravrai1
Last active July 27, 2017 04:05
Show Gist options
  • Save gauravrai1/b144dec60808724a116bee8e12267aad to your computer and use it in GitHub Desktop.
Save gauravrai1/b144dec60808724a116bee8e12267aad to your computer and use it in GitHub Desktop.
Snippet for AutoCompleteView (Android)
String[] cities = { "Mumbai","Chennai","Delhi","Banglore","Kolkata","Nagpur","Pune","Nashik","Ahemdabad","Vadodara","Kochin"};
ArrayAdapter<String> adaptercity = new ArrayAdapter<String>(this,android.R.layout.select_dialog_singlechoice, cities); //pass our array of string
AutoCompleteTextView acTextViewcity = (AutoCompleteTextView) findViewById(R.id.city);//initialize your view
acTextViewcity.setThreshold(1);//set the number of element to be choosen
acTextViewcity.setAdapter(adaptercity); //set the array within the adapter here
//custom names used to explain the code: cities,adaptercity,acTextViewcityand all the city names.
<AutoCompleteTextView
//attributes almost same as EditText
android:id="@+id/city"
android:layout_width="352dp"
android:layout_height="45dp"
android:background="@drawable/roundborder"
android:hint="City/Town"
android:inputType="text"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textColorHint="#e0e0e0"
android:textStyle="bold"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment