0

I want to fill progressbar when I swipe my hand on the phone. I think I should use scroll method or onfling method. But how can I understand how much I swipe? I use this code :

 @Override
        public   boolean  onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) 
        {       
             try {

                if(e1.getX()-   e2.getX()> min_dist) {

                       Toast.makeText(getBaseContext(), "Left Swipe", Toast.LENGTH_SHORT).show();

                } 
                else  if (e2.getX()- e1.getX()> min_dist  ) {
                          Toast.makeText(getBaseContext(), "Right Swipe", Toast.LENGTH_SHORT).show();

                }
              if(e1.getY() -e2.getY() > min_dist ) {
                         Toast.makeText(getBaseContext(), "Swipe up", Toast.LENGTH_SHORT).show();

                 } 
              else if (e2.getY()  - e1.getY()> min_dist ) {
                      Toast.makeText(getBaseContext(), "Swipe down", Toast.LENGTH_SHORT).show();

                 }
                } catch (Exception e) {
                    // nothing
                }

                        return true;
        }

But when I swipe my hand x to y it says sometimes e1.getX() - e2.getX() = 440 sometimes it says

e1.getX() -   e2.getX() =200

I do not understand. and I want to worry can I fill progressbar at the same time swipe?

user3086226
  • 93
  • 1
  • 6
  • 18
  • Maybe on the on touch metod, on the move, divide the arg1.getX() to the screen width, now you have the ratio. Set the progressbar value to maximumValue*ratio. – Boldijar Paul Dec 31 '13 at 08:31
  • But how can I set progressbar , it is like that prbar.setvalue=e1.getX() - e2.getX() ; because it is not stabil – user3086226 Dec 31 '13 at 08:51
  • Dont use scroll, use onTouch, at the move case. prbar.setProgress((arg1.getX()/screenWidth)*prbar.getMax()); – Boldijar Paul Dec 31 '13 at 08:53
  • @Paul I use your code but progressbar is not filling, I use the toast to make notification at the same time , it says the value is 65 but progressbar is not working – user3086226 Dec 31 '13 at 11:20

0 Answers0