AutoCompleteTextView

AutoCompleteTextView Widget



“An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

There is the Link for the Full Documentation of AutoComplete TextView by Android Developers :
       

In AutoCompleteTextView, first Create a Project named AutoCompleteTextView .  
Then we give the project file Details we have done in this project :

activity_main.xml :


<Relativelayout 
       android:id="@+id/activity_main" 
       android:layout_height="match_parent"
       android:layout_width="match_parent" 
       tools:context="com.pathantalabs.autocompletetextviewapp.MainActivity" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools">

    <Autocompletetextview 
         android:gravity="center" 
         android:hint="Countries" 
         android:id="@+id/autoCompleteTextView" 
         android:layout_alignparentleft="true" 
         android:layout_alignparentstart="true" 
         android:layout_alignparenttop="true" 
         android:layout_height="wrap_content" 
         android:layout_margintop="36dp" 
         android:layout_width="match_parent" 
         android:textsize="24dp">
    </Autocompletetextview>
</RelativeLayout>



MainActivity.java


package com.pathantalabs.autocompletetextviewapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {

    AutoCompleteTextView autoTV;
    String[] country_list =
            {
                    "amman","jordan",
                    "amsterdam","nertherlands",
                    "athens","greece",
                    "bangkok","thailand",
                    "beijing","china",
                    "berlin","germany",
                    "cairo","egypt",
                    "canberra","australia",
                    "copenhagen","denmark",
                    "dhaka","bangladesh",
                    "doha","qatar",
                    "dublin","ireland",
                    "helsinki","finland",
                    "jakarta","indonesia",
                    "kabul","afghanistan",
                    "kingston","jamaica",
                    "kuala lumpur","malaysia",
                    "london","unitedkingdom",
                    "lisbon","portugal",
                    "madrid","spain",
                    "manila","philippines",
                    "mexico city","mexico",
                    "moscow","russia",
                    "nairobi","kenya",
                    "nassau","bahamas",
                    "new delhi","india",
                    "ottawa","canada",
                    "oslo","norway",
                    "paris","france",
                    "prague","czech republic",
                    "pretoria","africa",
                    "pristina","kosovo",
                    "pyonyang","north korea",
                    "riyadh","saudi arabia",
                    "rome","italy",
                    "colombo","sri lanka",
                    "santiago","chile",
                    "seoul","south korea",
                    "singapore","singapore",
                    "sofia","bulgaria",
                    "stockholm","sweden",
                    "suva","fiji",
                    "taipei","taiwan",
                    "tashkent","uzbekistan",
                    "tbilisi","georgia",
                    "tehran","iran",
                    "tirana","albania",
                    "tokyo","japan",
                    "tripoli","libya",
                    "tunis","tunisia",
                    "ulaanbaatar","mongolia",
                    "vienna","austria",
                    "vientiane","laos",
                    "warsaw","poland",
                    "washington d.c","united states of america",
                    "wellington","new zealand",
                    "zagreb","crotia"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        autoTV = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);

        ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.select_dialog_item,country_list);
        autoTV.setThreshold(1);
        autoTV.setAdapter(adapter);
    }
}

For More Info Watch the VIdeo: 
AutoCompleteTextView on Youtube

Comments

Total Pageviews

6,832

Popular Posts

Difference between Activity and AppCompatActivity