外来片段相关code基本Android应用 [英] Extraneous fragment-related code in basic Android app

查看:99
本文介绍了外来片段相关code基本Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关Android的学习,我一直在下面的一本书的例子。这已经持续罚款,直到前几天,我告诉Eclipse来进行自我更新。现在,当我创建一个新的Andr​​oid应用程序的项目,也有在res /布局/,而不是一两个XML文件。此外,Java源代码是不同的。相反,好简单的(一个教程追随者)的onCreate这样的

For learning Android, I've been following examples in a book. It's been going fine, until a couple days ago I told Eclipse to update itself. Now when I create a new Android App project, there are two XML files in res/layout/ instead of one. Also, the java source is different. Instead of the nice simple (to a tutorial follower) onCreate like this

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_absolute_lay);
}

现在是这样的:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
}

我的问题是:这是怎么回事?相关的直接子问题是:难道我搞砸了一些默认设置在Eclipse,或者这是到Android刻意改变什么地方记录?我在哪里,现在把我的实验的学生质量和垃圾 - 哪个.xml?是否code我通常会放的onCreate()现在前或碎片处理业务之后去了?我们现在总是有处理片段而在此之前是有人可选?

My question is: what is going on? The relevant immediate sub-questions are: Did I screw up some default setting in Eclipse, or is this a deliberate change to Android documented somewhere? Where do I now put my experimental student-quality and junk - which .xml? Does code I would normally put in onCreate() now go before or after that fragment-handling business? Are we now always having to deal with fragments whereas before is was optional?

推荐答案

不是关于你的项目发生了什么事的想法。通常情况下,当Eclipse正在更新你不必是担心白白因为Eclipse无法更新后改变你的源文件。

Not idea about what happened in your project. Normally when Eclipse is updated you don't have to be worry for nothing because Eclipse can not change your source files after update it.

不要担心这一点。

在此和平code的:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
               .add(R.id.container, new PlaceholderFragment()).commit();
    }
}

在创建活动时,它加载在一个名为R.id.container(如果你preSS按住Ctrl键并单击该R.id.container顶部的一个容器,Eclipse是要打开的布局文件的.xml此组件)呼吁PlaceholderFragment类中的一个片段。

when the activity is created, it is loading in one container called R.id.container (if you press ctrl button and click on the top of this R.id.container, Eclipse is going to open the layout file .xml where this component is) one fragment called PlaceholderFragment class.

如果你想连续工作刚刚删除的.xml,并且不需要与此code覆盖您的code .java文件。不用担心这个。复制和放大器;粘贴在其中的一个顶部的code。

If you want continuous your work just delete the .xml and .java files that you don't need and overwrite your code with this code. Don't worry about it. copy & paste your code on the top of these one.

有关确保当您创建一个新的项目,尽量让看看是否有任何pre-配置来创建一个片段视图或类似的东西。

For sure when you create a new project, try so see if there is any pre-configuration to create a fragment view or something like that.

如果不清楚你的,问我。

If it is not clear for you, ask me.

这篇关于外来片段相关code基本Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆