Skip to content Skip to sidebar Skip to footer

Cannot Set String Array For Spinner Using Android Data Binding

I have a spinner now and I want to load the data to the spinner with data binding feature. I tried to find the way to declare the string array in the XML(https://developer.android.

Solution 1:

have you import the SparseArray ?

try this :

<data><import type="android.util.SparseArray"/></data>

Solution 2:

This is a very simple way to setup a spinner with a string-array from your resource's array.xml

<Spinnerandroid:layout_width="match_parent"android:layout_height="wrap_content"android:entries="@array/spinner_array_items"/>

The spinner_array_items should contain a list of items to be found in the spinner dropdown.

Solution 3:

Change SparseArray<String> to SparseArray&lt;String&gt;.

Solution 4:

Well my implementation logic is based on your's but used ArrayList instead SparseArray.

XML:

<data><importtype="java.util.ArrayList" /><variablename="cities"type="ArrayList&lt;String>"
        /></data><!-- Location --><Spinnerandroid:id="@+id/dd_city"android:entries="@{cities}"style="@style/dropdown"
    />

Now, we just need to bind our ArrayList to cities variable through Binding Class.

At least data will be bind : ).

TC.

Post a Comment for "Cannot Set String Array For Spinner Using Android Data Binding"