AppCompatAutoCompleteTextView

AppCompatAutoCompleteTextView is a view i.e similar to AppCompatEditText, except that it displays a list of completion suggestions automatically while the user is typing. A list of suggestions is displayed in drop down menu from which user can choose an item which actually replace the content of AppCompatEditText with that.

Class hierarchy
public class AppCompatAutoCompleteTextView extends AutoCompleteTextView implements TintableBackgroundView
java.lang.Object
↳ android.view.View
  ↳ android.widget.TextView
    ↳ android.widget.EditText
      ↳ android.widget.AutoCompleteTextView
        ↳ androidx.appcompat.widget.AppCompatAutoCompleteTextView

We Recommend to use new UI components i.e. androidx components


AppCompatAutoCompleteTextView Attributes

Attributes Description
android:completionHint This defines the hint displayed in the drop down menu.
android:completionHintView This defines the hint view displayed in the drop down menu.
android:completionThreshold This defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu.
android:dropDownAnchor This is the View to anchor the auto-complete dropdown to.
android:dropDownHeight This specifies the basic height of the dropdown.
android:dropDownHorizontalOffset The amount of pixels by which the drop down should be offset horizontally.
android:dropDownSelector This is the selector in a drop down list.
android:dropDownVerticalOffset The amount of pixels by which the drop down should be offset vertically.
android:dropDownWidth This specifies the basic width of the dropdown.
android:popupBackground This sets the background.

Create AppCompatAutoCompleteTextView in layout xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.appcompat.widget.AppCompatAutoCompleteTextView
        android:id="@+id/tvAutoComplet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Search for name"/>

</androidx.appcompat.widget.LinearLayoutCompat>

Create AppCompatAutoCompleteTextView Programatically
String[] names = new String[] {"John carlo", "Marry", "Tom King", "William", "Harry"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, names);
AppCompatAutoCompleteTextView autoCompleteTextView = new AppCompatAutoCompleteTextView(this);
LinearLayoutCompat.LayoutParams params = new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
autoCompleteTextView.setLayoutParams(params);

autoCompleteTextView.setAdapter(adapter);


AutoCompleteTvExActivity.java
package com.theitbulls.uicomponentex;

import android.os.Bundle;
import android.widget.ArrayAdapter;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;

public class AutoCompletTvExActivity extends AppCompatActivity {
    private AppCompatAutoCompleteTextView tvAutoComplete;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.auto_complete_ex_activity);

        String[] names = new String[] {"John carlo", "Marry", "Tom King", "William", "Harry"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, names);
        tvAutoComplete = findViewById(R.id.tvAutoComplet);
        tvAutoComplete.setAdapter(adapter);
    }
}


Download: AutoCompletTextViewEx.zip