slider - How to get fixed scale Vertical SlideBar working in Android? -


i trying vertical slide bar work in range 0-50, when user moves slide bar number on scale displayed in textview (live update slider moves).

having looked around have implemented slidebar using code here.

i new android , not sure how obtain value slider?

my code below:

verticalslidebar.java

import android.content.context; import android.graphics.canvas; import android.util.attributeset; import android.view.motionevent; import android.widget.seekbar;  public class verticalseekbar extends seekbar {      public verticalseekbar(context context) {         super(context);     }      public verticalseekbar(context context, attributeset attrs, int defstyle) {         super(context, attrs, defstyle);     }      public verticalseekbar(context context, attributeset attrs) {         super(context, attrs);     }      protected void onsizechanged(int w, int h, int oldw, int oldh) {         super.onsizechanged(h, w, oldh, oldw);     }      @override     protected synchronized void onmeasure(int widthmeasurespec, int heightmeasurespec) {         super.onmeasure(heightmeasurespec, widthmeasurespec);         setmeasureddimension(getmeasuredheight(), getmeasuredwidth());     }      protected void ondraw(canvas c) {         c.rotate(-90);         c.translate(-getheight(), 0);          super.ondraw(c);     }      @override     public boolean ontouchevent(motionevent event) {         if (!isenabled()) {             return false;         }          switch (event.getaction()) {             case motionevent.action_down:             case motionevent.action_move:             case motionevent.action_up:                 setprogress(getmax() - (int) (getmax() * event.gety() / getheight()));                 onsizechanged(getwidth(), getheight(), 0, 0);                 break;              case motionevent.action_cancel:                 break;         }         return true;     } } 

the main.xml file is:

     <com.test.verticalseekbar         android:id="@+id/seekbar1"         android:layout_width="wrap_content"         android:layout_height="440dp"         android:layout_alignbottom="@+id/mart1"         android:layout_marginright="120dp"         android:layout_toleftof="@+id/switch1" /> 

the main.java area confused about, have implemented following:

private seekbar seekbar1; seekbar1 = (seekbar)findviewbyid(r.id.seekbar1); 

this have hit limit. need setting fixed range slide bar, getting value live updated int.

thank offered.

i found didnt need fixed scale, , using following read value of vertical slider:

public class testslider extends activity implements onseekbarchangelistener{     private seekbar bar; // declare seekbar object variable     // declare text label objects     private textview textprogress,textaction;   @override     public void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         // load layout         setcontentview(r.layout.main);              bar = (seekbar)findviewbyid(r.id.seekbar1); // make seekbar object         bar.setonseekbarchangelistener(this); // set seekbar listener.          // make text label progress value         textprogress = (textview)findviewbyid(r.id.textviewprogress);         // make text label action         textaction = (textview)findviewbyid(r.id.textviewaction);      }   public void onprogresschanged(seekbar seekbar, int progress,             boolean fromuser) {         // todo auto-generated method stub          // change progress text label current seekbar value         textprogress.settext("the value is: "+progress);         // change action text label changing         textaction.settext("changing");     }  public void onstarttrackingtouch(seekbar seekbar) {         // todo auto-generated method stub         textaction.settext("starting track touch");      }   public void onstoptrackingtouch(seekbar seekbar) {         // todo auto-generated method stub         seekbar.setsecondaryprogress(seekbar.getprogress());         textaction.settext("ended tracking touch");          }  } 

hopefully answer helps in future.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -