I am trying to create RecyclerView
with use of DataBinding for Integer data, i have already tried with String data by declaring string-array
in string.xml
, here is answer from where i have taken reference.
Now i am trying to implement it with integer-array
but not able to access it from xml.
Here is my integer.xml
<integer-array name="hours">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
</integer-array>
here is my xml file
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:entries="@{@integerArray/hours}">
and my custom binding adapter
@BindingAdapter("entries")
public static void entries(RecyclerView recyclerView, Integer[] array) {
recyclerView.setAdapter(new SimpleArrayAdapter(array));
}
But it is showing me error line 1:0 token recognition error at: '@integerArray/'
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Identifiers must have user defined types from the XML file. hours is missing
Found solution from document itself, i was doing silly mistake. It should be intArray
instead of integerArray
, and in BindingAdapter
it should be int[]
app:entries="@{@intArray/hours}"
and adapter should be
@BindingAdapter("entries")
public static void entries(RecyclerView recyclerView, int[] array) {
recyclerView.setAdapter(new SimpleArrayAdapter(array));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With