Decimal values in seek bar android -
i working on android application in using seek bar. in range 0 - 20 , starting value 5. numeric values working fine, want make decimal values range should 0.0 20.0. code numeric given below:
seekbar seek=(seekbar) findviewbyid(r.id.seekbar1); seek.setprogress(5); seek.setonseekbarchangelistener(new onseekbarchangelistener() { @override public void onstoptrackingtouch(seekbar seekbar) { } @override public void onstarttrackingtouch(seekbar seekbar) { // todo auto-generated method stub } @override public void onprogresschanged(seekbar seekbar, int progress,boolean fromuser) { textview.settext( progress + " km");// + seekbar.getmax()); distance = progress; } });
xml seek bar:
<textview android:id="@+id/txtseekbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginbottom="10dp" android:text="5 km" android:textappearance="?android:attr/textappearancemedium" android:textcolor="@color/gray" />
i have used sample code decimal values not working. please me out here.
seekbar seek=(seekbar) findviewbyid(r.id.seekbar1); seek.setprogress(5); seek.setonseekbarchangelistener(new onseekbarchangelistener() { @override public void onstoptrackingtouch(seekbar seekbar) { } @override public void onstarttrackingtouch(seekbar seekbar) { // todo auto-generated method stub } @override public void onprogresschanged(seekbar seekbar, int progress,boolean fromuser) { double value = ((float)progress / 20.0); string yourprogress = string.valueof(value); textview.settext( yourprogress + " km");// + seekbar.getmax()); distance = (int) value; } });
you should make progress range 0 200 , multiply current progress 0.1f when changes. cheers.
seekbar seek=(seekbar) findviewbyid(r.id.seekbar1); seek.setprogress(5 * 10); seek.setonseekbarchangelistener(new onseekbarchangelistener() { @override public void onstoptrackingtouch(seekbar seekbar) { } @override public void onstarttrackingtouch(seekbar seekbar) { // todo auto-generated method stub } @override public void onprogresschanged(seekbar seekbar, int progress,boolean fromuser) { float currentprogress = progress * 0.1f; string yourprogress = string.format("%.1f", currentprogress); textview.settext( yourprogress + " km");// + seekbar.getmax()); } });
in xml layout add progress bar
android:max="200"
when want getprogress multiply 0.1f
float currentprogress = seekbar.getprogress() * 0.1f;
Comments
Post a Comment