ViewFlipper with clickable items

by Marc Reichelt » Fri, 16 Oct 2009 23:59:25 GMT


Sponsored Links
 i!

I am using the ViewFlipper to switch between different views by
implementing a swing (mouse down, move and release). This works great
with non-clickable items, e.g. a TextView.

But if the views are clickable items (such as buttons), the onTouch()
method of the ViewFlipper is not called. :-(
Does anyone know why this is so and how I can implement this "pseudo
gesture"?

I know that I could do this easily by using the 1.6 SDK and the new
gesture support, but my application is limited to 1.5.


Thanks in advance & regards

Marc Reichelt || http://www.marcreichelt.de/


PS: I developed a simple example so that you can see what I mean.



--------- Content of TestFlipper.java ---------
package com.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ViewFlipper;

public class TestFlipper extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final ViewFlipper flipper = (ViewFlipper) findViewById
(R.id.flipper);
flipper.setOnTouchListener(new OnTouchListener() {

private float oldX;

@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// save start X location
oldX = event.getX();
return true;

case MotionEvent.ACTION_UP:
// get old X location where the user
started the move
float currentX = event.getX();

// do not consume event if it is not
clear enough
if (Math.abs(currentX - oldX) < 25.0f)
return false;

// show previous view
if (oldX < currentX) {
flipper.showPrevious();
return true;
}

// show next view
if (oldX > currentX) {
flipper.showNext();
return true;
}
}

// do not consume this event by default
return false;
}
});

}
}
--------- End ---------



--------- Content of main.xml ---------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent&qu



Other Threads

1. installing ADT plugin for mac

I have eclipse with Java installed.

I used help>install new software to get the ADT plugin for Mac.   The
download operation completed but did not tell me where the files were
placed.

The help>install new software>already installed?  link seems to
indicate that the following software were installed:  Android DDMS,
Android Development Tools, Android Hierarchy Viewer

But, since I do not know where the SDK were unpacked, I am unable to
set the path for the SDK location at eclipse>preferences>android

What is the default location for mac?

-- 

2. Intercept incoming and outgoing Phone Call and text messages

This has been already discussed so many times. Please search for it. I am
pretty sure that you will find enough threads or discussions about this.


Kumar Bibek
http://techdroid.kbeanie.com
http://www.kbeanie.com







-- 

3. Passing objects to new intents

4. Voice Input Feature

5. Problem with SharedPreference

6. Honeycomb Preview: No Snapshot option when AVD manager launched from Eclipse

7. Android C++ Development with Visual Studio