android - How to increase or decrease counter using horizontally scrolling button -


i creating 1 android application in want add 1 horizontally scrolling button increase/decrease counter.

for instance if user scrolls button towards right, counter should increase 1 , scrolling left decrease counter 1.

please tell me should accomplish task. have @ attached image has function want.

i want counter increase when user scrolls particular button , not when swipes somewhere else on screen

enter image description here

you can use seekbar increase or decrease counter. simple example of layout can use might this:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <seekbar         android:id="@+id/seekbar"         android:layout_width="match_parent"         android:layout_height="wrap_content" />      <textview         android:id="@+id/counter"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="0" >     </textview>  </linearlayout> 

and code woul this:

import android.app.activity; import android.os.bundle; import android.widget.seekbar; import android.widget.seekbar.onseekbarchangelistener; import android.widget.textview;  public class mainactivity extends activity {      private textview counter;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          // selects textview holds value of counter         this.counter = (textview) findviewbyid(r.id.counter);          seekbar seekbar = (seekbar) findviewbyid(r.id.seekbar);         // sets initial value of seekbar (it must same initial         // value of counter)         seekbar.setprogress(0);         // sets max value of counter         seekbar.setmax(100);         seekbar.setonseekbarchangelistener(new onseekbarchangelistener() {          @override         public void onstoptrackingtouch(seekbar seekbar) {          }          @override         public void onstarttrackingtouch(seekbar seekbar) {          }          @override         public void onprogresschanged(seekbar seekbar, int progress,             boolean fromuser) {             // code runs when scroll seekbar left or right.             // if scroll left, counter decreases , if             // scroll right, counter increases             counter.settext(string.valueof(progress));         }     }); } 

}


Comments