1

I have an ImageView on each row of a ListView. I set an onLongClickListener for the ImageView on the ListView adapter as following:

picView.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub

            [-- my code for image long click--]

            return true;
        }
    });

In the Activity, I set OnItemClick for the ListView as following:

listViewWord.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                [-- my code for item click--]

                return;
            }
        });

The problem now is, consider the UI design, the Imageview is not large enough, every time I long click the ImageView and if the finger touch both the image area and the list item, both the [-- my code for image long click--] and [-- my code for item click--] will be triggered, which is not what I want. I want to ONLY trigger onLongClick when I long click the ImageView. Is there any method to intercept the touch event after the onLongClick be called? I have returned true in my onLongClick;

p.s. If I'm careful enough to only tap the image area, it works fine. So what I'm looking for is some code to intercept the touch event in my picView.setOnLongClickListener.

Any suggestion will be highly appreciated.

Vigor
  • 1,706
  • 3
  • 26
  • 47
  • Seems like some already faced this problem before --> http://stackoverflow.com/questions/7333608/ontouchevent-onclick-onlongclick-calls – Kody Jan 17 '15 at 20:00
  • @Kody: That is a completely different issue. – corsair992 Jan 17 '15 at 20:30
  • Can you share a sample project that can reproduce this, and describe which API level this is happening on? – corsair992 Jan 17 '15 at 20:38
  • hi @corsair992 The code above is from my real project. The api level is 8 of my project. Do you think you need more info? I think putting a lot of code here will mess up the question. The issue I described above is exactly the problem I met. – Vigor Jan 17 '15 at 20:49
  • I can't reproduce this on a Nexus 7 emulator with Lollipop. If you can create a minimal _sample_ project (not the real project) that demonstrates this behavior, and also describe which API level this is reproduced on (not the minimum or target API level) and/or which device, then I might take a look at it. You can add a link to a zip file containing the project, or publish it on Github/Bitbucket/Google Code/etc. – corsair992 Jan 17 '15 at 21:14
  • @corsair992 sorry my problem is not accurately described. I updated my question. My ImageView is quite small, so when I touch it, sometimes my finger will cover part of the list item area, the issue only happen in this situation. If I carefully limit my finger only in the imageview, it works fine. I'm thinking I can set the long click listener to the imageview's background layout, which is larger, it'll be ok. But still, I really want to know if there's other method. – Vigor Jan 18 '15 at 06:22
  • OK, sounds like there isn't any real issue then. You can set the long click listener over whatever layout you wish to confine it to. If the background layout is the area that you wish to respond to touch events, then you can set it on it. You can also provide padding for the `ImageView` to broaden it's touch consuming area if you wish. – corsair992 Jan 18 '15 at 06:28

0 Answers0