Android SeekBar example
The layout for the SeekBar.
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_radius" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="5dp" android:text="@string/radius"/> <SeekBar android:id="@+id/seekbar_radius" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="@integer/search_redius_max" android:layout_toRightOf="@+id/tv_radius" android:layout_toLeftOf="@+id/tv_radius_value"/> <TextView android:id="@+id/tv_radius_value" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="5dp" android:layout_alignParentRight="true" android:text="@string/radius_value"/> </RelativeLayout>
Initialize the SeekBar in the activity or fragment. The OnSeekBarChangeListener will update the label to show the current progress of the SeekBar.
tv_radius_value.text = if (seekbar_radius.getProgress() > 1) "${seekbar_radius.getProgress()} miles" else "${seekbar_radius.getProgress()} miles" seekbar_radius.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { } override fun onStartTrackingTouch(seekBar: SeekBar) {} override fun onStopTrackingTouch(seekBar: SeekBar) { tv_radius_value.text = if (seekbar_radius.getProgress() > 1) "${seekbar_radius.getProgress()} miles" else "${seekbar_radius.getProgress()} miles" } })
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts