How do i add swipe functionality to a button? - android

I want to show a button in a view.. If I swipe it left/right, I want to be able to get the next button.. How can I do it?
Each button represents an option of a menu..
Swiping should only work on the button.

The ViewPager class allows you to implement horizontal swiping through menu items. It can be set up to work on just on a small area of your Activity. You would use a fragment containing just a button in your case.
Take a look at this post on the Android Developers Blog for an example.

Related

How to pass click event from custom action bar to current page of android ViewPager?

I have an Activity with android.support.v4.view.ViewPager and custom ActionBar. There are three(0,1,2) pages in the ViewPager with page 1 set to be default page and user can slide left and right.
One Fragment class is used to show UI for each of the pages,which has a WebView which shows some html data which can be collapsed and viewed on a Button click in the WebView. Now there is also a button in the action, and I'm required to collapse and show these data on WebViewon the click of the Button in ActionBar. I've done it but the problem is that the items on the currently viewing page of ViewPager are not toggling on the click of the button in the actionbar, while that for the page on the left or right of it are working well.
How can I solve this problem?
What is the correct method of doing this?
You need to write 3 interfaces in 3 fragments.
You need to register this 3 fragments to you pager adapter/activity.
Whenever you click on the actionBar button check which is your
active/current page in the viewPager.
Perform click operation on the registered interface on the basis of
the active/current Page/Fragment.

Swiping in order to call another Activity in Android

I want to make something like transitions between ViewControllers in iOS 7 but in Android, is it possible?
Explanation: please look at image below, I have main Activity which has ViewPager inside, so we can swipe between Fragments. I want to call another Activity (or Fragment) from each Fragment (blue on image) swiping to bottom or to top but this action should be done smoothly like in ViewPager.
You can intercept swipe up and down gestures and set items in viewpager accordingly. Please read this guide on how to intercept swipes in various directions.

How to put tabs containing ListFragment on the left and a details panel on the right?

I have to show two tabs each containing ListFragment classes. On clicking any item of the list, it's details should open on the right panel on landscape views. This is much like the official Android fragments example.
What I want to achieve is that on the left side of the layout the list view should be in tabs, i.e. two list views within tabs. On clicking any item the details should open on the right. Till now, I can show tabs and details, but the details are not showing up on the right. They open as a new activity.
Tab Navigation can be an option, but due to some design restraints in my app, I can't use that. Please guide.
Please check this android blog http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html It has a complete tutorial of how to use fragments as a Master-Details View.
I came to a solution. I am explaining how I did it, in case someone needs it.
I wanted to make tabs on the left fragment. Due to design constraints, I could not use Tab Navigation, as I had to use List Navigation too.
So, I made a new fragment placed over the left fragment and inflated it with two buttons. On different button clicks, I used FragmentTransaction to add new fragment to the left fragment.
On button click listener I used fragmentTransaction.replace method.

Android swipe activity list

I have worked on "swipe" in android 3.0 and it's working fine. Now after swipping some pages(suppose to the right) I want all those pages to appear at the bottom(as options) so that I don't have to swipe all the pages (to the left) to get back to first page. I can directly select the desired page from those options and jump on to that activity.
Please help or tell me any good tutorial which can help.
Thanx..
Put some container layout at the bottom, add a listener to the swipe event, where you inflate / generate dynamically a corresponding item and add it to the container in the bottom. Add a click listener to the item, and in the click listener emulate swipe to the corresponding page...

Dynamically ViewPager flow of pages

I've used ViewPager to let the user flip left and right to navigate among pages of a given activity.
Is it possible to programatically control the flow of pages of the ViewPager?
For exemple:
If the user didn't fill a given EditText on the current page, I don't want him to be able to navigate to the next one.
Another case: If the user is currently on page 1 and if hi filled a given EditText with a specific value and the user flip right to left, I want him to go straight to the 5th page instead of the 2nd one.
By "flipping" you mean dragging with a finger or just using the ViewPager for animation?
If it's the former, you'll have to dynamically edit the children of the ViewPager to get the effect you want. You can override onInterceptTouchEvent() to block touch events until a page is completed.
However, I recommend disabling finger-dragging in the ViewPager (perhaps using onInterceptTouchEvent()) and then using setCurrentItem(4, true) to show the animation and navigate to a specific page. The logic you need can be implemented using buttons which will call setCurrentItem(4, true). For example, you can have a "Next->" button that is grayed out unless the form is completely completed. That will be more intuitive then the first option anyway.
Edit: 4 is just whatever child index you want to switch to.

Categories

Resources