D
D
Denis2016-08-26 00:34:27
Android
Denis, 2016-08-26 00:34:27

Why in custom AutoCompleteTextView onClick only works after getting focus?

I create a custom AutoCompleteTextView, when clicked, it opens all available options, like an ExpandableListView.

public class CustomAutoCompleteTextView extends AutoCompleteTextView implements View.OnClickListener, View.OnFocusChangeListener {



    public CustomAutoCompleteTextView(Context context) {
        super(context);
        setOnClickListener(this);
        setOnFocusChangeListener(this);
    }

    public CustomAutoCompleteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setOnClickListener(this);
        setOnFocusChangeListener(this);
    }

    public CustomAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOnClickListener(this);
        setOnFocusChangeListener(this);
    }

    @Override
    public void onClick(View view) {
        this.showDropDown();
    }


    @Override
    public void onFocusChange(View view, boolean b) {
        if(b)
        {
            this.showDropDown();
        }
    }
}

For some reason, onClick only fires if the element already has focus, i.e. only on the second click.
If someone knows what is the reason for this behavior, please explain.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-08-26
@lacredin

link, I think it will help,
that is, you need to rewrite ontouchlistener, onTouch calls onFocus, and that in turn calls onClick

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question