ListView, onFling(horizontal), gesture issues

by Wall-E » Thu, 19 May 2011 02:50:58 GMT

Sponsored Links
 So I have a listview using an arrayadapter.  I want to detect a
horizontal swipe/fling to toggle a view item to gone/visible inside
the listview.  What I've done to achieve this is to have a
SimpleGestureDetector to detect the fling.  I've added an
onTouchListener to the listview that returns if a fling/swipe was
detected.  If a swipe was detected, I set that view to either visible
or gone.  Now this works for the first item in my listview but not for
the others.  Inside of the onTouch method I have access to a View in
which I access my layout items. Also, the listview gets distorted and
does not refresh correctly.  I even call invalidate on the listview
after I've done the change.  So first off, am I going about this
correctly or is there a better/proper method to accomplish what I'm
trying to do?

Here is some of my code:

        gestureListener = new View.OnTouchListener()
            public boolean onTouch(View v, MotionEvent event)
                        ImageView deleteImageView = (ImageView)
                        if(deleteImageView.getVisibility() == View.GONE)
                    return true;
                return false;

        class MyGestureDetector extends SimpleOnGestureListener
            public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY)
                if (Math.abs(e1.getY() - e2.getY()) >
                    return false;
                // right to left swipe
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE &&
                        return true;
                else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE &&
                        return true;
                catch (Exception e)
                // nothing
                        return false;
                return false;


Re: ListView, onFling(horizontal), gesture issues

by Wall-E » Thu, 19 May 2011 06:07:06 GMT

 'm also noticing that in my layout that I inflate inside the
ListView, if I include a CheckBox, the behavior for the onClick for
the ListView isn't working, meaning, usually when you click/touch the
item in the ListView, it will be highlighted or change colors. When I
add a CheckBox, it doesn't highlight anymore and my
onListItemClick(...) listener never gets called. Is there a bug? or a
trick to getting this to work? If it matters, my layout is a
RelativeLayout(also tried with LinearLayout), with a CheckBox on the
far left, then a TwoLineListItem and finally an ImageView. If I just
remove the CheckBox, it will respond how a ListView normally should
respond but once I include the CheckBox it won't behave normally as
described above.

On May 18, 1:14pm, Wall-E <> wrote:


Sponsored Links

Other Threads

1. Menu key Problem

hi all
I am developing a music application..
When the music is playing I am pressing the red key.then soudn is
getting stopped.
then if I press the Menu key it will show  the locked screen.. but
my application is running an dmusic was playing.
is there any way to detect the menu key press in the application ?


2. Confused by Android testing framework

I'm attempting to use the JUnit-based testing framework supplied with 
Android 1.0r1...and I'm baffled.

I found the tests associated with the ApiDemos in the SDK. In the 
AllTests class, it says to run:

adb shell am instrument -w \

I do that, and I get:


and DDMS gives me an "Unable to find instrumentation info for..." warning.

But, that's OK, I want to run my own tests.

So, in a fresh activityCreator-created project, I:

1. Create an AndroidManifest.xml file:

<manifest xmlns:android=""
                <uses-library android:name="android.test.runner" />
                android:label="Tests for the heck of it"/>

2. Make a suite class in my xyz.test package:

public class XYZSuite extends TestSuite {
        public static Test suite() {
                return(new TestSuiteBuilder(XYZSuite.class)

3. Make a stupid test class in an sub-package:

public class SampleTest extends AndroidTestCase {
        protected void setUp() {
                // do something here
        protected void tearDown() {
                // do something here
        public void testStupid() {
        public void testStupider() {

4. Build and install the APK for all this on the emulator, bundling in a 
JAR of classes in the xyz namespace that I (eventually) want to test.

5. Run:

adb shell am instrument -w \

...and it too fails with INSTRUMENTATION_FAILED. This time, I get a 
different warning from DDMS:

"Unable to find instrumentation target package: xyz"

Where am I going wrong?

Thanks in advance!

Mark Murphy (a Commons Guy)
_The Busy Coder's Guide to Android Development_ Version 1.3 Published!


3. How can I launch the default Contact Application provided in SDK with my app

4. Using an autocomplete filled with information from a database query

5. SlideME: Sam 2.2 Release

6. Ksoap probleme!!! rejected Lorg/ksoap2/transport/ServiceConnectionMidp;

7. simulate key press