I have a project with 4tabs in it. All four tabs are within the activity_main xml file. The MainActivity Java file uses the tabhost to set the content of the tabs. One of my tabs has a list view and the other a map. Do I carry out all these events(loading the map,setting the list view) in the MainActivity class or I can implement a class for each layout so that the class is called when the focus changes to that tab? Kind of a newbie need some serious help. Not very familiar with tabs as well. Thanx. Dont know what sample code to attach as I havent tried much except implement some things in a different class and that never worked.
You can use a FragmentTabHost.
For each of your tabs create a Fragment and add it to the FragmentTabHost.
Here's a quick tutorial.
Each tab content should be an activity (or at least what i found in code samples), first time you activate a tab it will its activity onCreate(), and then if you clicked a tab that was already loaded that will call its onResume().
Here you can find a step by step tutorial for using tabs.
Related
I'm trying to create a layout that has a stationary footer with activities that slide behind it. I've been told to use Fragments, but that would mean that I would have to convert my already existing Activities to Fragments - right? Here is a diagram of what I'm trying to achieve: http://i.imgur.com/K8Iao.jpg
What I think #TarunMaheshwari is trying to say is that instead of having 3 activities (eg. classes with extends activity), replace it with extends fragment (obviously there are other minor changes you might have to make for the code to work) and then create a main activity (with extends FragmentActivity) that has the static footer you want which can call on the 3 different fragments.
Recommended readings:
http://developer.android.com/guide/topics/fundamentals/fragments.html
http://android-developers.blogspot.ca/2011/02/android-30-fragments-api.html
I believe using fragments is the right solution for your app. However, from what I understand from your question and comments, you really want to avoid using them. To use activities instead of fragments, implement a Tab Layout with a Tab Host and Tab Widget as explained in this tutorial. This solution allows you to use the tabs to switch between activities.
To align the Tab Host to the bottom of the screen, have a look at this tutorial.
I try to create a android application with tabHost and I would like to avoid to set intent(activity) for the content of these tabs.
I succeed to create my tabMenu but I would like to change the view of one tab.
How I can do that ?
For example I have one view for Tab1 and two views for Tab2 (when the user click on the button of Tab2_view1 then the content change to Tab2_view2 and the indicator doesn't change (stay on "tab2")).
I hope it is possible but I don't find the way to do that without using different activities for each tabs.
Maybe my conception is bad (I am novice in Android dev.)...
Thank you very much for your help,
Fred
Android has ActivityGroup for the same purpose that you are looking for. By using ActivityGroup you can show multiple views in a single Tab by maintaining the stack of the Views.
ActivityGroup Example 1
ActivityGroup Example 2
Fragment - Answer to me by hackbod
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.
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
I am working on an application where I am using the TabHost and I have four Tabs. Each of the tabs are given in a class MyTabHost that extends TabActivity.
Again I have one class that extends ActivityGroup and I have given all the tab classes in that class.
Now the problem is that when I move to another activity from one activity and when I come back to the previous activity, the position of the view gets refreshed and I don't want that. I want to maintain the view when I get back to the previously left activity on demand.
Is there any solution to anybody?
Thanks,
david
I am not exactly sure if I understand you correctly and without source it is even harder.
Having said this, In Zwitscher I am also using tabs and switching between them does not change the content. Have a look at this code snippet:
https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/TabWidget.java#L82
Perhaps this helps finding your issue.