Search code examples
androidandroid-layoutandroid-intentandroid-tabs

How to maintain custom tab on screen and change class without redrawing the tab again?


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.

Custom Tab 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.

I managed to create it using FragmentActivity and here is where you can refer to them : How to use custom iPhone tab in FragmentActivity?


Solution

  • 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.