'Android display item inside dropdown list

I have a TextInputLayout with style ExposedDropdownMenu. this TextInputLayout contains an AutoCompleteTextView. I can add a list item inside this AutoCompleteTextView using an adapter.

        mLightSensorGainTextInput = (AutoCompleteTextView) findViewById(R.id.paramLightSensorGain);
        String[] gainStrArray = new String[] {"1", "2"};
        ArrayAdapter<String> gainAdapter = new ArrayAdapter<>(this, R.layout.version_list_item, gainStrArray);
        mLightSensorGainTextInput.setAdapter(gainAdapter);

I would like to set one value displayed when I click a "setDefaultButton" but I have always the initial view: enter image description here

I tried :

mLightSensorGainTextInput.setListSelection(0);
mLightSensorGainTextInput.setSelection(0);

but none of the 2 methods shows the value expected which is : 1. Do you have any suggestion? Best regards Mich

Please here is more informations about what I expect. Only last operation (default button) does not work. enter image description here



Solution 1:[1]

Try setText():

mLightSensorGainTextInput.setText("xxx");

Solution 2:[2]

As your items are text-based, you can get the first item from the adapter by autoCompleteTextView.getAdapter().getItem(position); then to make it the current selection; set the text of the autoCompleteTextView to that item: mLightSensorGainTextInput.setText((mLightSensorGainTextInput.getAdapter().getItem(0)).toString());

Solution 3:[3]

The solution is to use the filter:

mLightSensorGainTextInput.setText("1", false);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sam Chen
Solution 2 Zain
Solution 3 Mich