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. where is Android shell configuration ?


Where is the android shell console ash configured ? If I want to change on
which uart the shell is displayed, like an /etc/inittab in normal
file-system ?


unsubscribe: [EMAIL PROTECTED]

2. only every other key press results in icon or selection highlighting

In porting android to an OMAP EVM board, I'm having an issue where D-
pad key presses (i.e. left/right/up/down) don't seem to cause the
screen to refresh such that the next icon is highlighted.  Based on
how the code reacts, the icon is actually active (i.e. ENTER causes it
to launch) but just not highlighted.  It seems as though every other
key press results in the screen being refreshed (such that every other
icon is highlighted as the directions keys are used to move around an
array of icons on the screen).  Is this a keyboard driver issue, a
frame buffer driver issue, or something else?  All other key related,
touchscreen related, and frame buffer related functionality seems



3. Android Windows driver gone

4. Web Service and Authentication

5. How does the bootloader legacy works?

6. On JITs (was Negative culture of Android Market reviews)

7. unable to use map application behind proxy