Android AutoCompleteTextView Control

AutoCompleteTextView application is same like as Google search. When you type in Google textbox, it give some suggestion automatically. This application same as Google Search.

Step 1.

Create new application with any name from file menu option.

File → New Project → Application name → select API → Add Blank Activity → Activity Name → finish.

Step 2.

In activity_main.xml layout file design your application.

Add following Controls:-

autocomplete textview

Step 3.

Import Package and write following coding in MainActivity.java class file.

    
    import android.widget.ArrayAdapter;
    import android.widget.AutoCompleteTextView;
    import android.widget.TextView;

	public class MainActivity extends ActionBarActivity {

    AutoCompleteTextView at;
    String name[]={"Akhtar","Akash","Arshi","Akhtar","Manzar","Mandeep","Manpreet"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        at=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
        ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_List_item_1,name);
        at.setAdapter(ad);
    }

Finally run your application. Type any name in textbox field which you have set in string.

autocomplete textview

Post Your Comment