How to auto select an item from an 'AutocompleteTextView' or simulate a click? ANDROID STUDIO

0

As an achievement that self-selects an item of ACTV without clicking, just setting the text that I need. that is automatically. If the received text is the same or if it shows an option that selects the first or the only one that it finds.

In this case, select "New Caledonia" . but without clicking.

Thank you very much.

    
asked by Juan Sepulveda 28.02.2018 в 17:11
source

1 answer

0

To solve this problem, what I did was

1.- create a handler to pause before reading the text.

Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { EditText.requestFocus(); // Darle foco EditText.setText(""+cantidad_); } }, 1000); // 1 segundo

2.- then copy the same action as in the "selectonclicklistener" of the Autocompletetexview in the TextWatcher in the method 'public void afterTextChanged (editable Editable)'. 2.-

 spproducto.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable)
        {
            // CODIGO AQUI
        }
    });
    
answered by 28.02.2018 в 20:27