+91-7906818313 / +91-7500893874 Monday - Sunday 10:00am - 06:00pm
How To Create Autocomplete Text View in Android

How To Create Autocomplete Text View in Android

Autocomplete Text View in Android

If you want to make an android app which has autocomplete text view. And you are also facing a problem in autocomplete text view then you should read this article. Here you can get all information about Autocomplete Text View in Android.




You should read this code:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    tools:context="sumit.net.autocompeletetext.MainActivity">

    <AutoCompleteTextView
        android:id="@+id/actv1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         />
</LinearLayout>

MainActivity.java

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

public class MainActivity extends AppCompatActivity {
AutoCompleteTextView actv;
    String name[]={"amar","ashok","amit","abhishek","sumit","vivek","aniket","manish"};
    ArrayAdapter<String>advp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        actv=(AutoCompleteTextView)findViewById(R.id.actv1);
        advp=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,name);
        actv.setAdapter(advp);
        actv.setThreshold(1);
    }
}




The output of Autocomplete Text View in Android

auto complete text view in anroid

Leave a Reply

Close Menu
Translate »