0

I am trying set values in a spinner for this I have the following code:

Strings.xml

<string-array name="entries_list">
    <item>A</item>
    <item>B</item>
    <item>C</item>
    <item>D</item>
    <item>E</item>
</string-array>

ListViewModel.java

...
public MutableLiveData<List<String>> entries = new MutableLiveData<>();

public ListViewModel(Application application){
    super(application);
    List<String> entries =  Arrays.asList(getApplication().getResources().getStringArray(R.array.entries_list));
    this.professions.setValue(entries);
}
...

layout_list.xml

....
<data>
    <variable
        name="listViewModel"
        type="com.myapp.ListViewModel" />
</data>
....
<Spinner
    android:id="@+id/spnEntries"
    app:entries='@={listViewModel.entries}'/>
....

But when I try to execute I get the next error:

****/ data binding error ****msg:Cannot find the setter for attribute 'app:entries' with parameter type android.arch.lifecycle.MutableLiveData> ...

Any idea that how resolve this?

Thanks.

Tlaloc-ES
  • 4,825
  • 7
  • 38
  • 84

1 Answers1

1

Please add full code for ViewModel and the Repository. Also try this and let me know if it works

android:entries="@array/entries_list"
Jiten Basnet
  • 1,623
  • 15
  • 31
  • That not solve the problem, really is the same name, but in different variable context then I could access to variable, but if change, I get the same error – Tlaloc-ES Feb 28 '19 at 10:11
  • With android:entries="@array/entries_list" appears and option in a dialog, but when pick one, not appear the value in the sppiner – Tlaloc-ES Feb 28 '19 at 15:09
  • I added android:selectedItemPosition="@={registerViewModel.positionSelected}" and this work perfectly, still can see the value in the spinner but this is maybe because styles, my new doubt is how can get the value form string array with positionSelected? – Tlaloc-ES Feb 28 '19 at 15:15
  • please take a reference from this link, anser by @Long Rager https://stackoverflow.com/questions/37874091/android-spinner-data-binding-using-xml-and-show-the-selected-values – Jiten Basnet Feb 28 '19 at 15:54