Show all items in AutocompleteTextView without writing text

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.


Solution 1:

You need to extend AutoCompleteTextView,

"When threshold is less than or equals 0, a threshold of 1 is applied.".

setThreshold

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).

Look at this example

Solution 2:

BETTER SOLUTION HERE

You don't need to customize your AutoCompleteTextView. Instead just call autoCompleteTextView.showDropDown() Whenever you need it.....cheers :)

Solution 3:

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;
        }
    });