Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply Touch Swipe on single page ,the page that is used for loading data dynamically?

I have used single page on which data is loaded again and again.

A same page is being used for loading data; ie headline, photo and description. Can you help me so that I can apply swipe function in it? I am building an application like Pulse News check it on the swipe function. I have built it in phonegap, HTML5, CSS3 and JavaScript and also jQuery mobile.

I know how to to swipe the pages, where are more than one page but there is only one page on which data is loaded dynamically and only the content is changed, so how should I add swipe to it so that it works on iPhone and Android?

like image 839
Akash Malhotra Avatar asked Sep 15 '12 11:09

Akash Malhotra


1 Answers

It doesn't matter how many pages you have in your app. You need to detect SWIPE action in your activity and reload data instead of really swiping pages. to do that: in your touch event listener, detect:

ACTION_MOVE

like this:

if(event.getAction() != MotionEvent.ACTION_MOVE)

even check the distance to make sure a SWIPE happened:

switch(event.getAction())
 {
     case MotionEvent.ACTION_DOWN:
              if(isDown == false)
              {
                     startX = event.getX();
                     startY = event.getY();
                     isDown = true;
              }
              Break;
              case MotionEvent.ACTION_UP
              {
                     endX = event.getX();
                     endY = event.getY();
                     break;
          }
}

calculate the distance then, if sounds like more than a click... consider it a swipe and reload your data good luck

like image 112
Masoud Dadashi Avatar answered Nov 08 '22 04:11

Masoud Dadashi