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. Any way to make localized resources separate downloads?

It's looking as if my first app will be about 200K in size, English-
only.  Each localization adds about 12K.  So far it's only available
on sourceforge where it has a few hundred downloads and already
volunteers have contributed three translations, so it seems possible
that once it's on the android marketplace translations will nearly
double its size.  That seems wasteful of users' phone storage when
most of them want only one language.  In the PocketPC version the
translations are separately downloadable .dll files -- which sucks for
lots of reasons but does allow users to manage how much space the app
consumes.  Is there any way to mimic this behavior on Android?  For
example, could I have the full-sized app offer to download a one-
language version of itself that would then replace the larger
version?  Or is there a mechanism I've missed close to what .dlls




2. Images in ListView in wrong places


I have a ListView which has rows that include an ImageView. I am
populating the ImageView with the following code (getting the image
from the SDCard if available):

        Bitmap bmp = BitmapFactory.decodeFile(filename);
        ImageView iv = getCoverImageView();

However when I scroll and the images are loaded they seem to turn up
in the wrong places.

The ListView is populated through a CursorAdapter:

        public void bindView(View row, Context ctxt, Cursor c) {
                SDIReleaseWrapper wrapper = (SDIReleaseWrapper) row.getTag();

        public View newView(Context ctxt, Cursor c,
                        ViewGroup parent) {
                LayoutInflater inflater = getLayoutInflater();
                View row = inflater.inflate(R.layout.release_row, parent, 
                SDIReleaseWrapper wrapper = new SDIReleaseWrapper(row);

                return row;

and the rows are populated with information from the database through
the wrapper. The TextViews in the rows show up fine, but the
ImageViews seem to have random effects.

I'm not really understanding the process of populating an ImageView in
the row or why the ImageView doesn't know which row to populate with
the image.

If someone could point me in the right direction that would be great.


3. Problem in getting height of contetn in Webview

4. EGL initialized failed

5. button background image scaled down by default?

6. Strange Media Player Behavior on EVO

7. kernel headers for android - how often ?