ViewFlipper with clickable items

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

Sponsored Links

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

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 ||

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

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

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. */
public void onCreate(Bundle savedInstanceState) {

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

private float oldX;

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) {
return true;

// show next view
if (oldX > currentX) {
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="

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

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


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