English 中文(简体)
是否可能(或可取)使用活动作为ActionBar s 导航标签或下拉导航的转换部件
原标题:Is it possible (or advisable) to use Activity as switched component of ActionBar s navigation tab or drop-down navigation
  • 时间:2012-05-23 02:49:20
  •  标签:
  • android

我有两个活动。其中之一是显示图表,另一个是显示派图表。我想将两者嵌入一个单一的启动活动。允许用户进行单击,以切换线图和派图表。

我知道ActionBar的导航标签, 或下降导航 是帮助我达到这个目的的最佳人选。

从“Adroid API”演示和http://developer.android.com/guide/topics/ui/ actionbar.html ,我意识到所有转换的部件都以 Fragment 而不是 Actionity 的方式执行。

  1. Does it mean that I need to port my previous 2 Activities into 2 Fragments, in order to embed them into ActionBar s tab navigation view/ drop-down navigation view?
  2. Is there any other ways I can do without porting? But, is it advisable as I do not find an official example by using Activity.
  3. In API demo, I realize most Fragment is implemented in the following pattern.

public class FragmentStack extends Activity {
    ...
    public static class CountingFragment extends Fragment {
        // CountingFragment never access any members in FragmentStack
    }
}

这样做有任何理由吗? 为什么他们没有CountingForfication 是一个分离的文件?

问题回答

如果您想要嵌入一个单一的活动, 最好的方式是使用碎片。 您可能也可以使用自定义视图, 但碎片有定义明确的生命周期, 并且可以处理很多细节。 因此, 将功能提取成碎片, 并且将活动仅作为弹壳进行, 嵌入碎片( 如果您仍然需要这样) 。 您可以以任何你喜欢的方式在碎片之间切换 : 使用按钮、 下载器或者适合您应用程序的任何其他 UI; 您不必使用动作栏 。 至于 3, 在不同的文件中定义碎片没有问题。 活动和碎片在样本中处于同一个文件中, 以便更容易地跟踪样本 。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签