I have a AutocompleteTextView and it works fine. When I write a word it shows the relevant result but I want to show all items without writing any word in AutocompleteTextView. How can I do that.
-
Try this link code may be help you.... http://stackoverflow.com/questions/15224027/custom-autocompletevview-like-facebook-comments-field-in-android/15247212#15247212 – Umesh Lakhani Mar 21 '13 at 10:33
-
It is not the actual solution that I want. Anyway thanks. – androidcodehunter Mar 21 '13 at 10:41
14 Answers
You need to extend AutoCompleteTextView,
"When threshold is less than or equals 0, a threshold of 1 is applied.".
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.AutoCompleteTextView;
public class InstantAutoComplete extends AutoCompleteTextView {
public InstantAutoComplete(Context context) {
super(context);
}
public InstantAutoComplete(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
}
public InstantAutoComplete(Context arg0, AttributeSet arg1, int arg2) {
super(arg0, arg1, arg2);
}
@Override
public boolean enoughToFilter() {
return true;
}
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (focused && getFilter()!=null) {
performFiltering(getText(), 0);
}
}
}
in xml
<AutoCompleteTextView ... /> to <your.namespace.InstantAutoComplete ... />
EDIT 1
Create new class named InstantAutoComplete then put this code into the class.
In your layout xml use this class like
then find this widget in your actity (onCreate method).

- 496
- 6
- 9

- 12,673
- 5
- 49
- 68
-
But the problem is I already extends Activity in that class and it is required. So cannot able to extend AutoCompleteTextView like your solution. Is there any way. – androidcodehunter Mar 21 '13 at 10:40
-
You dont need to extend your activty, it is new custom autocomplete textview, just create it and use in your layout. Pls look at edited answer – Talha Mar 21 '13 at 10:46
-
https://dl.dropbox.com/u/68130108/AutoComplateTextView.rar look at this example – Talha Mar 21 '13 at 10:53
-
7I get java.lang.NullPointerException at android.widget.AutoCompleteTextView.performFiltering(AutoCompleteTextView.java:841) at com.mybusiness.ui.view.InstantAutoComplete.onFocusChanged(InstantAutoComplete.java:35). Any suggestions? – bentzy Jan 27 '14 at 14:52
-
Works but doesn't show suggestions the first time when it receives focus. How do I rectify this? – GunnerFan Apr 03 '15 at 08:29
-
1"When threshold is less than or equals 0, a threshold of 1 is applied." What a crappy idea... But thank you for pointing that out. – SePröbläm Dec 06 '15 at 14:08
-
This is a InstantAutoComplete, if you not put more code you will get errors in a future, not recommended to me – Jan 20 '16 at 16:01
-
1@bentzy add a check for `getFilter()` to be non-null before calling `performFiltering()` – thijsonline Jun 03 '16 at 08:55
-
It seems `showDropDown()` still needs to be called along with `performFiltering(...)`, because sometimes the dropdown does not appear. – fikr4n Feb 11 '17 at 03:22
-
TextInputLayout does not seems to work properly with the extended version of AutoCompleteTextView. Anyone know how to fix it? – Allan Veloso Oct 22 '18 at 20:08
-
I have one question. I'm clearing my screen once user clicks on submit button, then im supposed to clear screen, im doing autotv.settext("") but soon after that suggestion drop down opening again. where as i want that only when user clicks on that autocompleteTextview. How can i do that ? – Sumukha Aithal K Jun 10 '19 at 06:37
-
See a solution of Jan Moravec (https://stackoverflow.com/a/52895155/2914140) to show the list on every click. – CoolMind May 29 '20 at 14:10
BETTER SOLUTION HERE
You don't need to customize your AutoCompleteTextView
. Instead just call autoCompleteTextView.showDropDown()
Whenever you need it.....cheers :)

- 4,817
- 2
- 34
- 36
-
2Unfortunately this does not always work. I'm not sure why, but on some devices seem to ignore the command when the text field is empty. – Ifrit Apr 29 '14 at 18:01
-
-
-
4This will only work first time. But if you write something and then clear it, It will show nothing. That is because you trying to show the popup for the current state of the adapter which is empty after filtering with empty string. – Simon K. Gerges Aug 17 '15 at 14:12
-
@SimonKarmy The popup doesn't show even when the dataset is not empty but the text is. Whenever filtering is performed with empty string I populate the dataset with some stored values. – tanay tandon Feb 25 '16 at 08:04
-
4You should use showDropDown() in both OnFocusChangeListener when focus = true and in OnTextChangeListener say afterTextChanged, when length = 0; – Leo DroidCoder Apr 17 '17 at 14:52
It Works for me:
add to your object next event methods:
myView.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
myView.showDropDown();
}
});
myView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
myView.showDropDown();
return false;
}
});

- 520
- 5
- 4
-
2I don't think you need both. Doesn't touching the View give it focus as well? – velocirabbit Oct 07 '15 at 20:30
-
It works for me. But I had to add "auto_complete_text_view.threshold = 1 " in addition with your answer – Aminul Haque Aome Feb 04 '20 at 07:12
This works for me perfectly, this is an easy way to resolve the problem:
final ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_dropdown_item_1line, usernameLists);
etUsername.setThreshold(1);
etUsername.setAdapter(adapter);
etUsername.setOnTouchListener(new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
if (usernameLists.size() > 0) {
// show all suggestions
if (!etUsername.getText().toString().equals(""))
adapter.getFilter().filter(null);
etUsername.showDropDown();
}
return false;
}
});

- 726
- 8
- 12
-
adapter.getFilter().filter(etUsername.getText().toString()); keeps the filter. – Joshy Francis Jul 07 '18 at 12:55
-
1thanks for "adapter.getFilter().filter(null);" it helps me show all items even autocompletetextview was filled with default value. – Rahmat Ihsan Apr 11 '19 at 22:32
-
-
It works, but as in other answers, it hides and shows the list on every click inside `AutoCompleteTextView`. Also after you typed a letter (and shrinked records count) it will show the full list when click. – CoolMind May 29 '20 at 13:34
You need to call requestFocus();
to show keyboard, otherwise keyboard does not pop up.
The method forcefully shows drop-down list.
autocomptv.setOnTouchListener(new OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
// TODO Auto-generated method stub
autocomptv.showDropDown();
autocomptv.requestFocus();
return false;
}
});

- 26,736
- 15
- 188
- 224

- 2,463
- 1
- 22
- 20
-
Thank you for `requestFocus()`! A good idea! It works, but don't forget to set `autocomptv.threshold = 1` (or `android:completionThreshold="1"`). Without it a list will hide after you type the first letter (and then appear again after the second letter). – CoolMind Jun 01 '20 at 16:51
-
Also see https://stackoverflow.com/questions/47107105/android-button-has-setontouchlistener-called-on-it-but-does-not-override-perform and https://stackoverflow.com/questions/32065086/custom-view-has-setontouchlistener-called-on-it-but-does-not-override-performcli/32065442 to avoid warnings. – CoolMind Jun 25 '20 at 15:48
-
you need to put those steps to make it work perfectly
1-in your xml put this
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/account_type_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_16sdp"
android:layout_marginTop="@dimen/_24sdp"
android:layout_marginEnd="@dimen/_16sdp"
android:background="@drawable/rounded_edt_with_border"
android:completionThreshold="0"
android:drawableRight="@drawable/ic_arrow_down"
android:hint="@string/account_type"
android:imeOptions="actionNext"
android:inputType="text"
android:padding="12dp"
android:textSize="@dimen/_15sp"
/>
you just need to set android:completionThreshold
to zero
2- in your java code put
mViewDataBinding.accountTypeSpinner.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus)
mViewDataBinding.accountTypeSpinner.showDropDown();
});

- 996
- 2
- 15
- 39
-
1It works, but if you press Back (and hide the list) and then click inside `AutoCompleteTextView` again, it won't show the list. After you type and erase symbols it will show the list. – CoolMind May 29 '20 at 11:51
-
this is happening because I use only `setOnFocusChangeListener` you could add `setOnClickListener` and repeat the same code and it should do the trick – Abdulmalek Dery May 29 '20 at 12:30
-
Thanks! I tried other solutions as well. I understood that the list will hide on every click inside `AutoCompleteTextView`. So, when using `setOnClickListener` it hides and shows the list (except first click). – CoolMind May 29 '20 at 14:14
use this :
text.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
text.showDropDown();
return false;
}
});
Nothing Custom Required.
I tried All solutions but in some case that does not work. For Example one solution work for first time but when you remove text it will not appear. So I dug more and found following solution.
Suggestions are welcome.
XML:
<android.support.design.widget.TextInputLayout
android:id="@+id/tl"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatAutoCompleteTextView
android:id="@+id/autoComplete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint Here" />
</android.support.design.widget.TextInputLayout>
Kotlin:
val adapter = ArrayAdapter<BusinessNoResult>(context, android.R.layout.select_dialog_item, listItems)
autoComplete.setAdapter(adapter)
//threshold specifies the minimum number of characters the user has to type in
//the
//edit box before the drop down list is shown
autoComplete.threshold = 0
//we have to add check for 0 number of character in edit text. When that
//happens, we will show pop up manually
autoComplete.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
//first check if length of input is 0
if(s?.length ?: 0 == 0){
//if you don't use handler with post delay, the API will hide pop
//up, even if you show it. There could be better ways to this, but
//I have implemented this and after 100 millis it gives an animated
//look
Handler().postDelayed({
//manually show drop down
autoComplete.showDropDown()
}, 100) // with 100 millis of delay
}
}
})
//when user focus out the view, drop down vanishes. When come back it will not
//show, so to cover this scenario add following.
autoComplete.setOnFocusChangeListener { _, hasFocus ->
//when gain focus manually show drop down
if(hasFocus)
autoComplete.showDropDown()
}

- 2,235
- 1
- 19
- 29
-
I removed `BusinessNoResult`, added `implementation 'com.google.android.material:material:1.2.0-beta01'`, changed `android.support.design.widget.TextInputLayout` to `com.google.android.material.textfield.TextInputLayout` and `android.support.v7.widget.AppCompatAutoCompleteTextView` to `AutoCompleteTextView`. As in other solutions, it shows the list, but when you click again or press Back button, it then won't show the list until write some symbols. – CoolMind May 29 '20 at 13:18
All answers are outdated. With material design, it becomes a lot easier and smooth. Make sure you put inputType as none for not to open the keyboard anymore.
XML
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/et_countries_list"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:hint="Demo hint"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="@+id/countries_list"
android:layout_width="match_parent"
android:inputType="none"
android:layout_height="60dp"
/>
</com.google.android.material.textfield.TextInputLayout>
Then just add prepare your adapter and add it.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, new String[]{
"Belgium", "France", "Italy", "Germany", "Spain", "Belgium", "France", "Italy", "Germany", "Spain"});
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
autoCompleteTextView.setAdapter(adapter);
You are done. It will work better than a spinner. You can set hint, error, helper as well.

- 625
- 7
- 12
If other solutions does not work for you try this instead. Popup is displayed always on click.
public class InstantAutoComplete extends AppCompatAutoCompleteTextView {
public InstantAutoComplete(Context context) {
super(context);
}
public InstantAutoComplete(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
}
public InstantAutoComplete(Context arg0, AttributeSet arg1, int arg2) {
super(arg0, arg1, arg2);
}
@Override
public boolean enoughToFilter() {
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
performClick();
}
return super.onTouchEvent(event);
}
@Override
public boolean performClick() {
if (getFilter() != null && !isPopupShowing()) {
performFiltering(getText(), 0);
showDropDown();
}
return super.performClick();
}
}

- 496
- 6
- 9
-
Thanks! Probably `onTouchEvent` is not needed. It shows the list when click. First hides and then shows. I think, this is a behaviour of the spinner to hide on many events. – CoolMind May 29 '20 at 14:08
-
First it worked very well until I added `InstantAutoComplete` to a complex layout. Then the keyboard started to hide. If revert back to `AutoCompleteTextView` it shows the keyboard and works as expected, but doesn't show full list ot items. If I remove all 3 methods inside `InstantAutoComplete`, it doesn't show the keyboard and even doesn't work as `AutoCompleteTextView`. Maybe some other attributes in the layout are guilty. So, it is a good solution, but check in complex layouts. – CoolMind Jun 01 '20 at 16:26
Here an approach with onclicklistener as I found tat onTouch was a bit irritating when trying to scroll. mOccupation is the AutocompleteTextView in question.
mOccupation=(AutoCompleteTextView) findViewById(R.id.actv_occupation);
ArrayAdapter<String> occupationAdapter=new ArrayAdapter<String>
(NewClientActivity.this,
android.R.layout.simple_list_item_1,
getResources().getStringArray(R.array.occupation_array));
mOccupation.setAdapter(occupationAdapter);
mOccupation.setKeyListener(null);
mOccupation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//mOccupation.setText(null);
((AutoCompleteTextView) view).showDropDown();
return;
}
});
I managed to put it all into a Textinputlayout with the following xml specifications:
<android.support.design.widget.TextInputLayout
android:id="@+id/lo_occupation"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="occupation"
android:focusableInTouchMode="false"<--this is the important part
android:id="@+id/actv_occupation"
android:ems="10"
android:completionThreshold="0"<--this too
/>
</android.support.design.widget.TextInputLayout>

- 2,887
- 1
- 13
- 35
It helped me:
private AutoCompleteTextView autoCompleteTextViewRFID;
...
autoCompleteTextViewRFID = binding.choiceFieldRFID;
List<String> rfidArray = databaseManager.readCowsRFID();
ArrayAdapter<String> rfidAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line, rfidArray);
autoCompleteTextViewRFID.setThreshold(1);
autoCompleteTextViewRFID.setAdapter(rfidAdapter);
...
autoCompleteTextViewTypeRange.setOnTouchListener((v, event) -> {
autoCompleteTextViewTypeRange.showDropDown();
return true;
});
XML:
<AutoCompleteTextView
android:id="@+id/typeRange"
android:gravity="center"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="40dp" />

- 13
- 3
I got a great solution to this. It's simple. This is just the drop-down and choosing from the options.
Make sure you add these two lines to XML.
android:completionThreshold="0"
android:focusableInTouchMode="false"
XML
<com.google.android.material.textfield.TextInputLayout
android:layout_marginTop="10dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/select_area"
android:layout_width="match_parent"
android:layout_height="52dp"
android:padding="10dp"
android:textSize="15sp"
android:singleLine="true"
android:drawableEnd="@drawable/ic_arrow_down"
android:completionThreshold="0"
android:focusableInTouchMode="false"
android:hint="Select an Area"
android:inputType="text"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
JAVA
area_autocomplete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
area.showDropDown();
}
});

- 1,420
- 14
- 23
-
This will show dropdown, but user cannot then type in it. This solution is better https://stackoverflow.com/a/60489021/1404257 – Haris May 18 '20 at 07:55
-
As in the solution of Abdulmalek Dery (https://stackoverflow.com/a/60489021/2914140) (if change to click listener) it hides and shows the list on every click. I can enter letters. – CoolMind May 29 '20 at 13:24
-
Agree with @Haris, it hides cursor, but you can enter letters. It is because of `android:completionThreshold="0" android:focusableInTouchMode="false"`. – CoolMind Jun 01 '20 at 16:07
You could simply use this single line of code
autoCompleteTextView.setThreshold(100);

- 29
- 3