I have read many post about this problem, usually due to the inclusion of clickable objects in the gridview but that's not my case. I have a framelayout with a imageview and a gridview, I moves both using ontouchlistener in gridview and it's works, but onItemClickListener don't trigger. My xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/layoutJuego" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <paricio.toni.caththemole.MyFrameLayout android:id="@+id/frame" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" > <ImageView android:id="@+id/fondo" android:layout_width="760dp" android:layout_height="760dp" android:layout_gravity="center" android:contentDescription="@android:string/untitled" android:scaleType="fitXY" android:src="@drawable/terrenoarena" /> <GridView android:id="@+id/gridView1" android:layout_width="640dp" android:layout_height="640dp" android:layout_gravity="center" android:columnWidth="80dp" android:horizontalSpacing="0dp" android:numColumns="8" android:scrollbars="none" android:stretchMode="columnWidth" android:verticalSpacing="0dp" > </GridView> </paricio.toni.caththemole.MyFrameLayout> MyFrameLayout is a simple framelayout extended to be bigger than screen. My gridview have only imageviews (64 in a 8x8 structure). It was working fine before when I used gridview.setOnTouchListener for moves myFrameLayout but I had shake so I changed to moves imageview and gridview, result? bye bye shake and bye bye onItemClickListener
gridview = (GridView) findViewById(R.id.gridView1); adaptador = new ImageAdapter(this); gridview.setAdapter(adaptador); gridview.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int desplazamiento[]={0,0}; fondo.getLocationOnScreen(desplazamiento); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mx = event.getX(); my = event.getY(); return true; case MotionEvent.ACTION_MOVE: curX = event.getX(); curY = event.getY(); fondo.scrollBy((int) (mx - curX), (int) (my - curY)); gridview.scrollBy((int) (mx - curX), (int) (my - curY)); mx = curX; my = curY; return true; case MotionEvent.ACTION_UP: curX = event.getX(); curY = event.getY(); fondo.scrollBy((int) (mx - curX), (int) (my - curY)); gridview.scrollBy((int) (mx - curX), (int) (my - curY)); return true; } return false; } }); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Log.i("miTraza","OnItemClick"); // Don't trigger ... } }); I think that I could get position for gridview cell calculating manually with onTouchListener and events ACTION_DOWN and ACTION_UP consecutives (without ACTION_MOVE) but I want let it as last option.
Thanks for your help.