I implemented a gallery, and inside it I have many listviews from left to right. For some reason Gallery works great with all views but not with listview. With listview, whe
I had have the same problem. And the solution is less than simple.
listView.setFocusableInTouchMode(false);
Use OnInterceptTouchEvent to get Touch Events from your child. And make some modification in onScroll and onTouchEvent of your Gallery
OnItemSelectedListener mOnItemSelected = new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView> parent, View view,
int position, long id)
{
view.requestFocusFromTouch();
}
@Override
public void onNothingSelected(AdapterView> parent)
{
}
};
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
onTouchEvent(ev);
return scrollingHorizontally;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if(Math.abs(distanceX)>Math.abs(distanceY) || scrollingHorizontally == true){
scrollingHorizontally = true;
super.onScroll(e1, e2, distanceX, distanceY);
}
return scrollingHorizontally;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
scrollingHorizontally = false;
break;
default:
break;
}
super.onTouchEvent(event);
return scrollingHorizontally;
}