Android Fixed Paging

Asked

Viewed 671 times

1

I have a gridView I’m populating through a WebService. The problem begins when I want to trigger an event let’s say clico by sliding the screen left or right I know there is a pageview, but I don’t want to change the screen I just want the user to feel a change or whatever the data is loaded after the gesture but don’t pay to a next screen.

Being clearer as a calendar where the grid remains the same but changes only the values. I thank you.

  • Let’s see if I understand the scenario, you have a Gridview that represents the days of a month (a calendar). And you want to somehow change the elements of this Gridview when performing a certain action. Correct?

  • Exact while sliding left or right trigger an event(method I have to popular the grid) while moving right increase 1 month to left decreases 1 month.

  • You can assign this event to a gridview, because I was able to create but the event only shoots outside the gridview and not on top of it.

  • In fact, the GridView "absorbs" the event because it is "scrollavel" and has the treatment of click and longclick in the items. You would have to create your own GridView superimposing the method onTouchEvent and perhaps the method onInterceptTouchEvent. Detect if there was horizontal movement, do its action and do not leave the action of GridView standard rotate. If not horizontal you need to let the standard treatment rotate.

1 answer

0


This might work for you. You can use the method onTouchEvent in your Activity as the example taken from the site android Developer.

public class MainActivity extends Activity {

@Override
public boolean onTouchEvent(MotionEvent event){ 

int action = MotionEventCompat.getActionMasked(event);

switch(action) {
    case (MotionEvent.ACTION_DOWN) :
        Log.d(DEBUG_TAG,"Action was DOWN");
        return true;
    case (MotionEvent.ACTION_MOVE) :
        Log.d(DEBUG_TAG,"Action was MOVE");
        return true;
    case (MotionEvent.ACTION_UP) :
        Log.d(DEBUG_TAG,"Action was UP");
        return true;
    case (MotionEvent.ACTION_CANCEL) :
        Log.d(DEBUG_TAG,"Action was CANCEL");
        return true;
    case (MotionEvent.ACTION_OUTSIDE) :
        Log.d(DEBUG_TAG,"Movement occurred outside bounds " +
                "of current screen element");
        return true;      
    default : 
        return super.onTouchEvent(event);
}      

}

  • I think it is worth adding that along with this solution, to discover the speed/direction of the movement it is worth looking at this tutorial: http://developer.android.com/training/gestures/movement.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.