Android - how to make a complex tabbed app with views

The first question is about overflowing the stack, apologies if it is poorly formed.

I am developing a relatively sophisticated tabbed application and have already set up the basics before meeting the information that ActivityGroup and TabActivity are outdated, and the preferred model is using views.

I had no problems using views, this is a matter of architecture, not syntax (which is why I did not post any code). In particular, how do I need to restructure the application to use views instead of running Intent actions.

The application has five tabs; two have one layout, no problem. The remaining three tabs launch an ActivityGroup with 2-5 different actions (for example, a tab that performs an action for parameters, when each view is clicked, a new action starts that performs this specific setting, pressing the "Back" button returns you to wider functions / presentation of settings). If I were to store each Tab as a TabActivity, it would still be pretty easy to change these internal transitions to views, and not to individual actions.

The main question is to use ONLY views, there is no TabActivity / Activity group at all. The vast majority of my research is a discussion of whether to use "Actions" or "Views", or about the specific syntax. I could not put together a clear idea of ​​how to MAKE a transition to representations throughout the application.

  • If I did this, would the entire application now be launched in one action - which is hosting the tabbed layout?

  • If (1) is true, how can this be done? Despite the fact that the ActivityGroup is out of date, all the documentation on Android still claims that it is preferable to use separate actions for certain aspects of the functionality, which makes sense. Did the Android development team simply decide that the cost of the stack and device made the TabActivity implementation inefficient?

  • If the application runs in one Office that manages different views for each tab (and then different views INTERACT the tab when necessary), should I have one huge onClick method to handle all clicks from any interactive view, processing input based on which species is active? Or should I register and cancel all my listeners programmatically?

  • When using one action, will not any click listener or any broadcast receiver work all the time, consuming resources even if necessary?

  • With one action, the Back button will exit the entire application from anywhere in its functionality. If I use views, will I consistently override onBackPressed () and carefully control the application to make it behave "like an Android application?"

  • I THINKING ABOUT THIS TOTALLY WRONG? Perhaps I'm inadvertently trying to recreate the functionality of ActivityGroup and TabActivity using views instead, when I have to use a completely different approach to using tabs and views.

When people at Google say that we should no longer use actions as tabs, and Mr. Mark Murphy so categorically agrees, I tend to believe. I simply could not investigate the switching method without resorting to re-typing many of the activity functions manually (which would probably include a lot of dirty hacks).

Thanks in advance for anyone who wants to tackle such a vague and rewritten topic.

+7
source share
3 answers

Using Fragments is the new standard for executing tabbed ui elements in style, I think you must have simply lost sight of them because they went missing on all your questions. Good luck.

Remember that using the compatibility library provides fragment support up to 1.6.

And here is a simple Google recommended tutorial on using fragments inside TabHost.

+2
source

About 3) Divide your application into as many operations as you have different parts of the application. Today I’ll even go for Fragements, which can be easily compiled for different layouts when you, for example. make an app for your phone and tablet. In most cases, you can simply configure onClick listeners in the corresponding xml layout definition files as follows:

 <ImageButton android:id="@+id/new_tweet_back_button" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="left" android:onClick="done" android:src="@drawable/back_button" android:layout_below="@id/CharCount" /> 

Here the android:onClick points to a method that implements the handler. You do not need to unregister.

And instead of tabs, I would go to ViewPager, which makes imo much more natural, just changing my views, scrolling left and right (see, for example, the G + application or the application on the market)

+1
source

As a final answer to my own question:

Using fragments in DID tabs solves all of these problems.

So, instead of activity-determining tabs containing other actions, I have one big FragmentActivity function that sets and switches views of various fragments. The click methods defined in XML for each tab view are FragmentActivity, and I decided that each onClick calls the corresponding method in the corresponding fragment (passing context if necessary), so the code for managing each view can programmatically remain in the corresponding class.

THIS IS FOR A PHONE USING THE COMPATIBILITY PACKAGE, not a tablet or a cell, so I can not speak for those who, unfortunately.

This solution seems to have worked for me. I recommend to anyone looking at the same issue to check:

thepsuedocoder blog post: http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/

Android documentation for snippets: http://developer.android.com/guide/topics/fundamentals/fragments.html

Fragment tabs API demo version http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/index.html#Fragment

0
source

All Articles