I've been just looking at the demo and code for the ViewPager class in the android compatibility library; http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/index.html
What I want to create is;
A TabHost with tabs.
Each tab displays a List.
When an item in the List is selected it starts a new Activity.
The new Activity slides in to the space that the List was in, so the tabs are still visible.
Pressing the back button removes the new Activity and displays the original List.
I read about using an ActivityGroup but that class is deprecated so I refuse to use it.
I've looked at the Fragement demo examples for ViewPager and TabHost and feel like I'm looking for a combination of both of those things, but I'm a bit stuck on if it's even possible to do?
Thanks!
I've found a way to do this using ViewFlipper inside a tab. Then using custom in and out animations to slide between views.
Related
I have an Activity which contains a TabLayout and a ViewPager. The first tab contains a calendar and the second tab contains a timer.
Tapping on a date in the first tab should display a fragment with some event details while simultaneously hiding or removing that menu tab.
To this end, how can I use a FrameLayout as a fragment container when my layout already contains a ViewPager? Should I create a new Activity to get what I want, or is there a more efficient solution?
What you are describing is basically a list/details pattern. In short, yes, you should create a new activity for the details. It is the expected flow of an android app and it makes the implementation for you so much easier.
I am new to Android programming. I started building an app using YouTube tutorials but I am a little bit confused and facing a problem. Should I use fragments or activity in my sliding tab? I am working on an Android project of employee attendance and payroll so I am thinking of using a slide tab (something like the screenshot below). The 1st tab may contain a form to add an employee and after adding it, will display information in list view and the other may contain salary. Should I try fragment or activity for my tabs?
A fragment is always located in an activity.
So you wil always need an Activity and then add the fragment to the activity.
if you say you want to slide?
you probably mean a viewpager, that can have n fragments. the viewpager needs a special viewpageradapter. where you define how many fragments you want. and at which index what fragment needs to be shown
First - sorry for the newbish question.
I've started building an app that has a single Activity and a navigation drawer. Each menu item loads a new fragment in the middle frame layout.
I want to create another fragment that:
has tabs
allows for swipe scrolling
It seems like the only way to do this is to create add a ViewPager and PagerTabStrip. All the tutorials I've read indicate the ViewPager requires extending out to FragmentActivity. I have a few questions:
Am I doing anything wrong by replacing the fragment content when navigating menu options?
If what I am doing is ok, is there anyway to incorporate swipe navigation without calling FragmentActivity?
If I need to use FragmentActivity for this one page, I'm assuming I'll call change pages via Intent. Doing so would result in losing the click actions in the navigation drawer. Do I have to call (or duplicate) my code from one activity to another?
EDIT
Sorry about the confusion. Here's what I'd like my application do:
Open app. MainActivity starts. Navigation drawer loads. Main content is loaded via a fragment.
User opens navigation drawer and selects this new menu item I'm creating. It is a new fragment that loads in the frame (like the other menu items). However, it has tabs and supports swiping.
ViewPager is just usual descendant of View so it can't require using of FragmentActivity.
It's absolutely ok.
You don't need to use FragmentActivity. I suppose you just read tutorial about "Implementation of drawer" where author of the tutorial used FragmentActivity.
Can't understand what do you mean. Pages of ViewPager is just views not activities. You don't need to use Intent.
PS Actually I can't understand your problem at all. It's absolutely unclear why you don't want to use FragmentActivity.
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.
I am using TabHost in my application.
When I click on any one of the TabHost, it will display corresponding activity.
What I want is when i swipe on that activity it should display another Activity
I have used a ViewFlipper in the Activity(ChildActivity).
I am using example given here ....
The problem is : Its displaying the Activity that is loaded initially. Its not flipping the views as i wanted.
You can check out the code used in the Google I/O scheduler app. It has a class called FlingableTabHost. You would not need a ViewFlipper for this.
http://code.google.com/p/iosched/source/browse/trunk/src/com/google/android/apps/iosched/ui/ScheduleActivity.java
I would just catch the swipe on the tab's activity and then programmatically change the tab. Dont mess with something inside the tab.
Also, using viewFlippers, maybe you dont needs tabs.
Android Gestures
Swipe Action