Android: Use findViewById instead of getChildAt

More futureproof if anything else is added to the layout.
This commit is contained in:
Lioncash 2014-12-28 20:33:24 -05:00
parent 4221999c6e
commit 038b968698
2 changed files with 4 additions and 4 deletions

View File

@ -10,14 +10,14 @@
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:id="@+id/sliderSeekBar"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Sample Text"
android:id="@+id/textView"
android:id="@+id/sliderTextView"
android:textStyle="bold"/>
</LinearLayout>

View File

@ -40,8 +40,8 @@ public class SliderPreference extends DialogPreference implements SeekBar.OnSeek
LayoutInflater inflater = LayoutInflater.from(getContext());
LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.slider_layout, null, false);
m_seekbar = (SeekBar)layout.getChildAt(0);
m_textview = (TextView)layout.getChildAt(1);
m_seekbar = (SeekBar)layout.findViewById(R.id.sliderSeekBar);
m_textview = (TextView)layout.findViewById(R.id.sliderTextView);
if (shouldPersist())
m_value = Integer.valueOf(getPersistedString(Integer.toString(m_value)));