Search code examples
javaandroidandroid-arrayadapter

Array adapter don't show items after using set Text function


I have a Button and setOnClickListener, where i create simple Linked List and Array Adapter

LinkedList<Double> rangeList = new LinkedList<>();
     for (double j = -20; j <= 30; j += 1) {
          rangeList.add(j / 10); }

ArrayAdapter<Double> arrayAdapter = new ArrayAdapter<>(requireContext(), R.layout.dropdown_item, rangeList); //Collections.singletonList(range)
            binding.idInjectionTimeData.setAdapter(arrayAdapter); //idInjectionTimeData is AutoCompleteTextView in xml

Now everything works. But, if I just want to set initial value to my binding field (doesn't matter, what value), my application don't want to show values, that i set in my Array Adapter.

binding.idInjectionTimeData.setText("1.3");

In the debugger, I noticed that before using setText my array Adapter object has a mObject field with all values , and after using setText, mObject has only one value , which I used in setText, and the entire list of the Adapter's array has moved to mOriginalValues.

In short: I want my application to show my adapter like that.

But after setText, the field is initialized, but stop showing my adapter list.

What is the problem? What i can read to know more about that? Or maybe there is a better, different way to do it?


Solution

  • SetText filters out the values of the adapter, you'll have to use the override of setText that takes in 2 parameters, text and filter