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

  • Home
  • SEARCH
  • 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 8715359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:49:29+00:00 2026-06-13T05:49:29+00:00

i’m a n00b programmer and need a lot of help. Just for tutorial purpose,

  • 0

i’m a n00b programmer and need a lot of help.

Just for tutorial purpose, I want to make simple flora & fauna (plant & animal) encyclopedia

I want to make my home screen drag-able just like the Android’s home screen. Swipe right to open Plant page and swipe left to open Animal page.
I don’t know how to make the transition effect. So we can drag it halfway to peek what’s in next page and just drag back to cancel it

Can you guys share a link to make the drag-able screen?

Thanks before

[Edit]

@Agarwal
I tried the code from your Link2 and it’s not working

I try to test whether the gesture detected or not by putting Toast inside the inner class but the Toast isn’t shown. The Link1 is basically the same though.

and from the looks of the code, I think it can’t make my screen drag-able like in Android’s home screen

my code:

public class Home extends Activity implements OnClickListener {
    private GestureDetector gestureDetector;
    View.OnTouchListener gestureListener;
    ImageButton flora, fauna;
    Intent go;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    initialize();

    gestureDetector = new GestureDetector(new SwipeGestureDetector());
    gestureListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }
    };
}

private void initialize() {
    //find view by id to image button
    //set onClickListener to image button
}

public void onClick(View v) {
    //normal switch and case for each button

}

private void onLeftSwipe() {
    Toast t = Toast.makeText(Home.this, "Left swipe", Toast.LENGTH_LONG);
    t.show();
    go = new Intent("test.apps.FLORA");
    startActivity(go);
}

private void onRightSwipe() {
    Toast t = Toast.makeText(Home.this, "Right swipe", Toast.LENGTH_LONG);
    t.show();
    go = new Intent("test.apps.FAUNA");
    startActivity(go);
}

private class SwipeGestureDetector extends SimpleOnGestureListener {
    private static final int SWIPE_MIN_DISTANCE = 50;
    private static final int SWIPE_MAX_OFF_PATH = 200;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        try {
            Toast t = Toast.makeText(Home.this, "Gesture detected", Toast.LENGTH_SHORT);
            t.show();
            float diffAbs = Math.abs(e1.getY() - e2.getY());
            float diff = e1.getX() - e2.getX();

            if (diffAbs > SWIPE_MAX_OFF_PATH)
                return false;

            // Left swipe
            if (diff > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                Home.this.onLeftSwipe();
            } 
            // Right swipe
            else if (-diff > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                Home.this.onRightSwipe();
            }
        } catch (Exception e) {
            Log.e("Home", "Error on gestures");
        }
        return false;
    }

}
}
  • 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-06-13T05:49:30+00:00Added an answer on June 13, 2026 at 5:49 am

    I realise this is an old question but for anyone else wondering why the above code does not work it is because he has not set the OnTouchListener to a View object. This is why his swipe “event” is not being picked up, because nothing is listening for it.

    He could add this line to set swipes on his image button (though you would probably want a better View object then this):

    flora.setOnTouchListener(gestureListener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.