How can I get a specific Activity from TabActivity or TabHost?
I tried TabHost.getChildAt(), but a View instance can't be casted to an Activity instance.
Or how do you get an Activity which is running in background?
I couldn't find TabActivity.getLocalActivityManager().getActivity().
For me it worked using TabActivity.getLocalActivityManager().getCurrentActivity().
found the answer: just use TabActivity.getLocalActivityManager().getActivity()
I know this isn't what you're looking for, but I HIGHLY recommend not using TabActivity. In all the projects I've worked on, we wound up yanking it out and just using buttons that look like tabs.
I also think its deprecated in 3.0, and certainly Ice cream. They push the action bar. I'd look for one of the available action bar libraries.
Related
I am developing an android app, where I want to put action bar for phones below API 11.
I am following the below link.
http://hmkcode.com/add-actionbar-to-android-2-3-x/
I am making use of the v7 support library, and I am able to get the actionbar. But, the problem is I want to add a navigational listener or tab listener to the action bar. How is it possible.
Please help! Thanks in Advance.
You should use ActionBarSherlock. It is an excellent library of tools that allow you to use Action Bars in older phones and is widely used. The catch is that all your Activities will need to extend SherlockActivity instead of Activity and you have to be careful to call methods like getSherlockActivity() in Fragments instead of getActivity().
I prefer HoloEverywhere library
It allows much more than ActionBarSherlock, but makes your app ~3Mb bigger in size
I am sure you have not seen this
http://developer.android.com/guide/topics/ui/actionbar.html
Let me try to make my question much clearer here. Supposed I have a custom tab created by using buttons and images in XML layout and it looks like this.
Each of these buttons, should call a class. Normally, Intent is used to call new class when onClick. But the whole layout would be redrawn when I call any of the classes via Intent.
Intent intent1 = new Intent(TabBar.this, Favourites.class);
startActivity(intent1);
I tried using TabHost and it worked, but my project requires me to use a custom tab bar.
I also tried the solution to this Dynamically change view inside view in Android, which is similar to what I wanted, (switching layouts and maintaining the tab bar below it), which worked as well.
My goal is to maintain the custom tab that I have, and change the classes instead of layout without redrawing the custom tab bar everytime I click on every buttons. With classes, I can run different functions and call different activities.
I googled a lot on this but couldn't seem to find a solution or reference. Can somebody guide me? Thanks in advance.
Update :
I'm new in Android, and after attempting many times, I decided to try out codes from AdilSoomro to achieve what I wanted, http://adilsoomro.blogspot.com/2011/06/iphone-like-tabs-in-android.html which is to create custom tabs that looks like iPhone tabs. However, this project uses TabActivity that is now deprecated in Android 4.1. I attempted to change it to FragmentActivity after referring to other sources that uses Fragments for tabs.
http://android.codeandmagic.org/2011/07/android-tabs-with-fragments/
http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/
I managed to create it using FragmentActivity and here is where you can refer to them :
How to use custom iPhone tab in FragmentActivity?
You can use TabHost control to achieve this. Go through this post
It explains all the possibilities. It also includes using custom tab bar defined in the xml file.
One of the way to achieve this is create footer and use it in all your activity. Like This. And Let me know its useful as per your requirement or not.
I really want to get this to work, but I feel like I've been floundering about for hours. I'm starting up a new app and want to try to follow the UI guidelines as close as possible, which for anything below ice-cream sandwich seems to mean I need to use ActionBarSherlock. Looking at the example here it looks like it should be straightforward.
I try to implement it and it doesn't work because FragmentActivity does not have a getSupportActionBar() method.
Taking a look at the demo app and it seems they don't use FragmentActivity, they use SherlockActivity. Well, SherlockActivity does have a getSupportActionBar() method, so that's promising. Continuing on with the example for a while...
Okay, now it seems the com.actionbarsherlock.app.ActionBar.TabListener doesn't pass FragmentTransaction to its events? Not only that, but the SherlockActivity doesn't have a getSupportFragmentManager() method...
Am I (hopefully) just doing something completely wrong? How do I keep encountering all these issues that no one else is? I feel like I'm going nuts here. The only potentially related issue I've found is here and it's not very useful.
You need to extend from SherlockFragmentActivity instead of only SherlockActivity or SherlockFragment. This way you will get access to ABS and the Fragment Support.
I ran into a similar problem trying to get a map view and fragments to work with actionbarsherlock. See my post on the mailing list.
The solution I came up with was to get the sources for the compatibility library and modify the FragmentActivity to extend a SherlockActivity instead of a standard android Activity.
Then you'll need to compile the sources for the support library along with your app(in some fashion).
In my case I went an additional step to modify the SherlockActivity to extend MapActivity, but since you didn't mention maps, you wouldn't need to do that.
There may be other solutions, but this at least got things to work for me.
I would recommend the mailing list as this project seems to be changing frequently.
Try to use extend from com.actionbarsherlock.app.SherlockFragmentActivity and take a look at https://github.com/inazaruk/examples/tree/master/MapFragmentExample to see how to use a Map with Fragments.
Can I implement a tab host which will remain in overall application and works through out the application .
and
Also can i implement the tab host on the top and on the bottom of the same activity.
Any tutorial any help please....
Thanks
This is possible if you use Activity Group. But still it is deprecated and hence you cannot use it for newer versions of android. But still, you can go through what it is and try to implement it.
ActivityGroup Example
http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
http://gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity
So now since Activity Groups are deprecated what is the alternate strategy we can make use of? Here is the solution for this problem.
Go for fragments or Views.
I have pasted the comment which I recieved from Commonsware regarding the ActivityGroup.
You never needed ActivityGroup to use tabs. You can put views in tabs, for example (github.com/commonsguy/cw-android/tree/master/Fancy/Tab). Going forward, tabs are in the action bar on Honeycomb, typically using fragments. You can achieve the same functionality on previous versions of Android using ActionBarSherlock.
I am doing an application similar to Viber or Linphone, a SIP application basically. I have a main tabhost at the bottom of the screen. And inside each tab I set different activities(for example the historic). I have done this using ActivityGroup. Is that the right approach? As I have seen that ActivityGroup is deprecated, but I dont want to use fragments(most of phones dont support API 11). I have seen the ViewPager component, could be also an alternative? I guess I can change the event onFlip with my finger for the onClick on a specific botton. Am I doing it right using Activitygroup, or should I change to another component?
Usually the kind of thing you are describing can be done using a simple TabActivity.
I'm not sure why you decided to use ActivityGroup, but regarding your hesitation related to fragments - you can use the Compatibility library, which will give you fragment support for older platforms, albeit with some limitations.