I want to implement a SeekBar that automatically updates a TextView, for the actual value, the maximum value and a minimum value. I derive from SeekBar and define 3 named attributes with the format
being reference
.
In the constructor, I get a TypedArray
by calling obtainStyledAttributes()
. TypedArray
contains a lot of getters for every kind of attribute types. What I am missing is some kind of Object getReference()
or int getReferenceId()
.
How do I obtain the value for a reference attribute?
Edit:
I have an attribute definition for a class MinMaxSlider
, that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MinMaxSlider">
<attr name="min" format="integer" />
<attr name="valueView" format="reference" />
</declare-styleable>
</resources>
a snipped out of the layout definition looks like this:
<LinearLayout
style="@style/ParameterLabelLayout"
android:orientation="horizontal">
<TextView
style="@style/ParameterSliderLabel"
android:text="min. Interval" />
<TextView
android:id="@+id/min_connection_interval_slider_value"
style="@style/ParameterSliderValue"/>
</LinearLayout>
<com.roche.rcpclient.MinMaxSlider
style="@style/ParameterSlider"
android:id="@+id/min_connection_interval_slider"
android:max="3200"
custom:valueView="@id/min_connection_interval_slider_value"
custom:min="1"/>
Here, the MinMaxSlider
should reference one of the TextViews above to display its current value there.
From within the constructor of MinMaxSlider
, I can lookup the min attributes value.
If I try to lookup the valueView attribute as an integer, I always get the default value (0), not R.id.min_connection_interval_slider
as I would expect.
Edit: the right function to lookup a reference
seems to be getResourceId
. The obtained integer id can be used to use findViewById
later, when the overall object hierarchy is constructed.
In my case, I register an OnSeekBarChangeListener()
and lookup the View in the callback, when the callback is fired.