Android AutoCompleteTextView for auto complete texts under an EditText

This example demonstrates how to use the AutoCompleteTextView in Android. AutoCompleteTextView is similar to EditText except that it can show a dropdown list of suggested texts while you type

arrays.xml which contains the suggested texts



    
        January
        February
        March
        April
        May
        June
        July
        August
        September
        October
        November
        December
    

AutoCompleteTextView view in an Activity layout.




    

public class MainActivity extends AppCompatActivity {

    AutoCompleteTextView autoCompleteTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String[] months = getResources().getStringArray(R.array.months);
        autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.months);
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, months);
        autoCompleteTextView.setAdapter(adapter);
        autoCompleteTextView.setThreshold(1);
    }

}

Complete example in Github

Search within Codexpedia

Custom Search

Search the entire web

Custom Search