Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8588445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:48:15+00:00 2026-06-11T22:48:15+00:00

I have read many post about this problem, usually due to the inclusion of

  • 0

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 8×8 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:48:16+00:00Added an answer on June 11, 2026 at 10:48 pm

    In the end I had to perform manually OnItemClick inside OnTouch. This is the code I used, the method adaptador.getPosition (gridview, (int) x, (int) m) returns the selected position on the screen click. I’ve tried using pointtoposition (int, int) but returns me the wrong position.

        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:
                        click = true;
                        mx = event.getX();
                        my = event.getY();                     
                        return true;
                    case MotionEvent.ACTION_MOVE:
                        curX = event.getX();
                        curY = event.getY();
                        if (click && Math.abs(mx-curX)<5 && Math.abs(my-curY)<5) {
                            Log.i("miTraza","movimiento pequeño");
                            click = true;
                            return true;
                        } else {
                            click = false;
                        }
                        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:
                        if (click) {
                            int position = adaptador.getPosition(gridview, (int)mx, (int)my);
                            if (position>=0 && position<=63) {
                                gridview.performItemClick(gridview, position, 0);
                            }
                            click = false;
                        } 
                        return true;
                }
                return false;
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read through many post on Stackoverflow about this problem, but I can't seem
I have read many questions about Android, J2ME and RecordStore , but I still
I have read many questions about the facebook login but until not I didnt
I have read many article about this one. I want to hear from you.
I just read this post about why new-line warnings exist, but to be honest
I have read many answers to questions about dynamically resizing NSWindows and nothing has
I have read many answers regarding this still i am getting confused if i
I have read many question about improving the performance of C++ and C code
I have read so many times, here and everywhere on the net, that mutexes
I have found many questions here about storing values in viewstate, but haven't found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.