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)
            {
                if(gestureDetector.onTouchEvent(event))
                {
                        ImageView deleteImageView = (ImageView)
v.findViewById(R.id.deleteSourceImageView);
                        if(deleteImageView.getVisibility() == View.GONE)
                        {
                                deleteImageView.setVisibility(View.VISIBLE);
                        }
                        else
                        {
                                deleteImageView.setVisibility(View.GONE);
                        }
                        dataListView.invalidate();
                    return true;
                }
                return false;
            }
        };


        class MyGestureDetector extends SimpleOnGestureListener
        {
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY)
            {
                try
                {
                if (Math.abs(e1.getY() - e2.getY()) >
SWIPE_MAX_OFF_PATH)
                {
                    return false;
                }
                // right to left swipe
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
                {
                        return true;
                }
                else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
                {
                        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 <bashee...@gmail.com> 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 \
com.example.android.apis.tests/android.test.InstrumentationTestRunner

I do that, and I get:

INSTRUMENTATION_FAILED: 
com.example.android.apis.tests/android.test.InstrumentationTestRunner

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="http://schemas.android.com/apk/res/android"
                package="xyz.test"
                android:versionCode="1"
                android:versionName="1.0.0">
        <application>
                <uses-library android:name="android.test.runner" />
        </application>
        <instrumentation
                android:name="android.test.InstrumentationTestRunner"
                android:targetPackage="xyz"
                android:label="Tests for the heck of it"/>
</manifest>

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

public class XYZSuite extends TestSuite {
        public static Test suite() {
                return(new TestSuiteBuilder(XYZSuite.class)
                                .includeAllPackagesUnderHere()
                                .build());
        }
}

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

public class SampleTest extends AndroidTestCase {
        protected void setUp() {
                // do something here
        }
        
        protected void tearDown() {
                // do something here
        }
        
        public void testStupid() {
                assert(true);
        }
        
        public void testStupider() {
                assert(false);
        }
}

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 \
xyz.test/android.test.InstrumentationTestRunner

...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)
http://commonsware.com
_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