Home > other >  Android display item inside dropdown list
Android display item inside dropdown list

Time:05-12

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

CodePudding user response:

Try setText():

mLightSensorGainTextInput.setText("xxx");

CodePudding user response:

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

  • Related