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.
Please add full code for ViewModel and the Repository. Also try this and let me know if it works
android:entries="@array/entries_list"