Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7597311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:07:39+00:00 2026-05-30T22:07:39+00:00

I have a TabHost that has two ViewFlippers, and inside each ViewFlipper are three

  • 0

I have a TabHost that has two ViewFlippers, and inside each ViewFlipper are three ListViews. I would like to have left<->right gesture listener for the ViewFlipper to slide between the three ListViews. The Up/Down motion for the ListViews seems to work, but I cannot seem to get the ViewFlipper to work.

SessionView

Sessions.java (TabActivity)

public class Sessions extends TabActivity {

    private Guide guide;
    private String LOG_TAG = "Sessions Activity";

    // TabHost
    private TabHost tabhost;
    private ViewFlipper viewFlipperDay0;
    private ViewFlipper viewFlipperDay1;
    private TextView trackTitle_day0;
    private TextView trackTitle_day1;
    private GestureDetector gestureDetectorDay0;
    private GestureDetector gestureDetectorDay1;
    private ListView lv_day0_trackA;
    private ListView lv_day0_trackB;
    private ListView lv_day0_trackC;
    private ListView lv_day1_trackA;
    private ListView lv_day1_trackB;
    private ListView lv_day1_trackC;

    private ArrayList<Session> sessionList_day0_trackA;
    private ArrayList<Session> sessionList_day0_trackB;
    private ArrayList<Session> sessionList_day0_trackC;
    private ArrayList<Session> sessionList_day1_trackA;
    private ArrayList<Session> sessionList_day1_trackB;
    private ArrayList<Session> sessionList_day1_trackC;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle b = this.getIntent().getExtras();
        if (b!=null) {
            this.guide = (Guide) b.getSerializable(GUIDETYPE);
            Log.d(LOG_TAG,"Got guide through intent Serializable");
        } else {
            Log.e(LOG_TAG,"Unable to get guide through Intent");
        }
        setContentView(R.layout.sessions);

        this.trackTitle_day0 = (TextView) this.findViewById(R.id.session_track_desc_day0);
        this.trackTitle_day0.setText("Track A");
        this.viewFlipperDay0 = (ViewFlipper) this.findViewById(R.id.session_viewflipper_day0);
        this.trackTitle_day1 = (TextView) this.findViewById(R.id.session_track_desc_day1);
        this.trackTitle_day1.setText("Track A");
        this.viewFlipperDay1 = (ViewFlipper) this.findViewById(R.id.session_viewflipper_day1);

        this.gestureDetectorDay0 = new GestureDetector(new SessionGestureDetector(this.viewFlipperDay0));
        this.gestureDetectorDay1 = new GestureDetector(new SessionGestureDetector(this.viewFlipperDay1));

        // set up gesture swiping of tracks with animations (left/right only)
        //    up/down events and those which are too diagonal or squigly are ignored
        viewFlipperDay0.setOnTouchListener(new OnTouchListener()
        {
            public boolean onTouch(View v, MotionEvent event) {
                if (gestureDetectorDay0.onTouchEvent(event)) {
                 return true;
                } else {
                 return false;
                }
            }
        });
        viewFlipperDay1.setOnTouchListener(new OnTouchListener()
        {
            public boolean onTouch(View v, MotionEvent event) {
                if (gestureDetectorDay1.onTouchEvent(event)) {
                 return true;
                } else {
                 return false;
                }
            }
        });

        // load views into viewflipper
        /// Add Tracks
        Log.d(LOG_TAG,"Creating Track Views");
        View view_day0_trackA = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
        View view_day0_trackB = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
        View view_day0_trackC = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
        View view_day1_trackA = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
        View view_day1_trackB = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
        View view_day1_trackC = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);

        Log.d(LOG_TAG,"Adding Track Views to ViewFlippers");
        addViewToDayFlipper0(view_day0_trackA);
        addViewToDayFlipper0(view_day0_trackB);
        addViewToDayFlipper0(view_day0_trackC);
        addViewToDayFlipper1(view_day1_trackA);
        addViewToDayFlipper1(view_day1_trackB);
        addViewToDayFlipper1(view_day1_trackC);

        Log.d(LOG_TAG,"Assigning ListViews");
        this.lv_day0_trackA = (ListView) view_day0_trackA.findViewById(R.id.SessionListView);
        this.lv_day0_trackB = (ListView) view_day0_trackB.findViewById(R.id.SessionListView);
        this.lv_day0_trackC = (ListView) view_day0_trackC.findViewById(R.id.SessionListView);
        this.lv_day1_trackA = (ListView) view_day1_trackA.findViewById(R.id.SessionListView);
        this.lv_day1_trackB = (ListView) view_day1_trackB.findViewById(R.id.SessionListView);
        this.lv_day1_trackC = (ListView) view_day1_trackC.findViewById(R.id.SessionListView);
        //http://pareshnmayani.wordpress.com/tag/android-custom-listview-example/

        // get sessions
        //this.guide = this.getGuide();
        Log.d(LOG_TAG,"Getting Session info for each track");
        this.sessionList_day0_trackA = guide.getSessionsByTrack(0,0);
        this.sessionList_day0_trackB = guide.getSessionsByTrack(0,1);
        this.sessionList_day0_trackC = guide.getSessionsByTrack(0,2);
        this.sessionList_day1_trackA = guide.getSessionsByTrack(1,0);
        this.sessionList_day1_trackB = guide.getSessionsByTrack(1,1);
        this.sessionList_day1_trackC = guide.getSessionsByTrack(1,2);

        Log.d(LOG_TAG,"Assigning SessionAdapters");
        final SessionListAdapter lv_day0_trackA_adapter = new SessionListAdapter(this, this.sessionList_day0_trackA);
        final SessionListAdapter lv_day0_trackB_adapter = new SessionListAdapter(this, this.sessionList_day0_trackB);
        final SessionListAdapter lv_day0_trackC_adapter = new SessionListAdapter(this, this.sessionList_day0_trackC);
        final SessionListAdapter lv_day1_trackA_adapter = new SessionListAdapter(this, this.sessionList_day1_trackA);
        final SessionListAdapter lv_day1_trackB_adapter = new SessionListAdapter(this, this.sessionList_day1_trackB);
        final SessionListAdapter lv_day1_trackC_adapter = new SessionListAdapter(this, this.sessionList_day1_trackC);

        Log.d(LOG_TAG,"Setting Adapters");
        lv_day0_trackA.setAdapter(lv_day0_trackA_adapter);
        lv_day0_trackB.setAdapter(lv_day0_trackB_adapter);
        lv_day0_trackC.setAdapter(lv_day0_trackC_adapter);
        lv_day1_trackA.setAdapter(lv_day1_trackA_adapter);
        lv_day1_trackB.setAdapter(lv_day1_trackB_adapter);
        lv_day1_trackC.setAdapter(lv_day1_trackC_adapter);

        Log.d(LOG_TAG,"ListView OnClickListenters being assigned");
        lv_day0_trackA.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
                // item click listener for listview
                Session session = (Session) lv_day0_trackA_adapter.getItem(position);
                Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
            }

        });
        lv_day0_trackB.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
                // item click listener for listview
                Session session = (Session) lv_day0_trackB_adapter.getItem(position);
                Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
            }

        });
        lv_day0_trackC.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
                // item click listener for listview
                Session session = (Session) lv_day0_trackC_adapter.getItem(position);
                Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
            }

        });
        lv_day1_trackA.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
                // item click listener for listview
                Session session = (Session) lv_day1_trackA_adapter.getItem(position);
                Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
            }

        });
        lv_day1_trackB.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
                // item click listener for listview
                Session session = (Session) lv_day1_trackB_adapter.getItem(position);
                Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
            }

        });
        lv_day1_trackC.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
                // item click listener for listview
                Session session = (Session) lv_day1_trackC_adapter.getItem(position);
                Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
            }

        });

        tabhost = getTabHost();
        tabhost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
        tabhost.addTab(tabhost.newTabSpec("day0").setIndicator(createTabView(tabhost.getContext(), "Friday")).setContent(R.id.session_tab_layout_day0));
        tabhost.addTab(tabhost.newTabSpec("day1").setIndicator(createTabView(tabhost.getContext(), "Saturday")).setContent(R.id.session_tab_layout_day1));
        tabhost.setCurrentTab(0);

        Log.d(LOG_TAG,"Finished?");
    };

    private static View createTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }


    // Add view to viewflipper
    public void addViewToDayFlipper0(View view) {
        viewFlipperDay0.addView(view);
    }
    public void addViewToDayFlipper1(View view) {
        viewFlipperDay1.addView(view);
    }

    // Custom Gesture Adapter
    public class SessionGestureDetector extends SimpleOnGestureListener {

          private static final int SWIPE_MIN_DISTANCE = 120;
          private static final int SWIPE_MAX_OFF_PATH = 250;
          private static final int SWIPE_THRESHOLD_VELOCITY = 200;
          private ViewFlipper vf;

          public SessionGestureDetector(final ViewFlipper vf) {
              super();
              this.vf = vf;
          }

          public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
           System.out.println(" in onFling() :: ");
           if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
            return false;
           if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
             && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            vf.setInAnimation(inFromRightAnimation());
            vf.setOutAnimation(outToLeftAnimation());
            vf.showNext();
           } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
             && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            vf.setInAnimation(inFromLeftAnimation());
            vf.setOutAnimation(outToRightAnimation());
            vf.showPrevious();
           }
           return super.onFling(e1, e2, velocityX, velocityY);
          }
        }

    private Animation inFromRightAnimation() {
        Animation inFromRight = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, +1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        inFromRight.setDuration(500);
        inFromRight.setInterpolator(new AccelerateInterpolator());
        return inFromRight;
    }

    private Animation outToLeftAnimation() {
        Animation outtoLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, -1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        outtoLeft.setDuration(500);
        outtoLeft.setInterpolator(new AccelerateInterpolator());
        return outtoLeft;
    }

    private Animation inFromLeftAnimation() {
        Animation inFromLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, -1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        inFromLeft.setDuration(500);
        inFromLeft.setInterpolator(new AccelerateInterpolator());
        return inFromLeft;
    }

    private Animation outToRightAnimation() {
        Animation outtoRight = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, +1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        outtoRight.setDuration(500);
        outtoRight.setInterpolator(new AccelerateInterpolator());
        return outtoRight;
    }
}

sessions.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_vertical"
        android:background="#222222">       
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout android:id="@+id/session_tab_layout_day0"
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent"
                android:background="#F0E0B2">
                <TextView
                    android:layout_width="fill_parent"
                    android:gravity="center_horizontal"
                    android:layout_height="wrap_content"
                    android:textColor="#8e9f13"
                    android:background="#006772"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:id="@+id/session_track_desc_day0"
                    android:text="@string/session_track"></TextView>
                <ViewFlipper
                    android:id="@+id/session_viewflipper_day0"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                </ViewFlipper>
            </LinearLayout>
            <LinearLayout android:id="@+id/session_tab_layout_day1"
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent"
                android:background="#F0E0B2">
                <TextView
                    android:layout_width="fill_parent"
                    android:gravity="center_horizontal"
                    android:layout_height="wrap_content"
                    android:textColor="#8e9f13"
                    android:background="#006772"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:id="@+id/session_track_desc_day1"
                    android:text="@string/session_track"></TextView>
                <ViewFlipper
                    android:id="@+id/session_viewflipper_day1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                </ViewFlipper>
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>

session_track.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/session_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#F0E0B2">
    <ListView
        android:id="@+id/SessionListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

session_two_line_list.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"
  android:layout_height="70dip"
  android:padding="6dip">
    <TextView
      android:id="@+id/session_title"
      android:text="Session Title"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center_vertical"
      android:textSize="22dip"
      android:textColor="#006772"/>
    <TextView
      android:id="@+id/session_time"
      android:text="08:00-09:00"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:singleLine="true"
      android:textSize="13dip"
      android:textColor="#006772" />
</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:07:40+00:00Added an answer on May 30, 2026 at 10:07 pm

    Don’t use a ViewFlipper, use a ViewPager. It’s a relatively late addition to the SDK that was created for exactly this sort of GUI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tabhost with three tabs. Each is an activity. I would like
I have a TabActivity that has a TabHost with two tabs. Each tab has
I have an activity that has a TabHost containing a set of TabSpecs each
I have three tabs that each has its own Activity. The tabs are as
Hey, I have a TabHost with two tabs, each with an Activity. The first
I have a custom TabHost that adds tabs like this private void setTab(View view,
I have Main Activity. That has 4 tabs ( TabHost ). I have overridden
I have an app that has 2 tabs. Each tab loads an xml file
I have an app that has a viewflipper to keep tabs in view at
I have a problem that sounds like this: I have a TabHost and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.