I have a GridView
where I load a preview image over the GridView
. While my preview is shown I want to disable scrolling. My code looks like that:
grid.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
preview.setVisibility(View.GONE);
return true;
} else if(event.getAction() == MotionEvent.ACTION_MOVE) {
Log.d("test", "isShown: " + preview.isShown());
return preview.isShown();
}
return false;
}
});
Pretty simple, but this does not work perfect. Scrolling is disabled by consuming the events, but it seems that the first move event gets every time executed on the GridView
and it moves for some pixels just one time.
What confuses me is that I get not isShown: false
messages in the logcat after seting preview
to visble. So far this is also no obvious reacing condition. This means that all events which get cought by my listener returns true
as expected.
I read this almost dublicates and many more:
But there is the point about how to disable it. I figgered that out my self.