如何在Android App中定义主类? [英] How to define the main class in an Android App?

查看:261
本文介绍了如何在Android App中定义主类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android的新手,我从developer.android.com下载了一个示例,我想使用其布局创建一个新类,并修改应用程序的主类以从另一个布局开始.

I'm very newbie in android, I download an example from developer.android.com and I want to create a new class with his layout and modify the main class of the application to start with another layout.

我该如何实现? (开始类的修改).

How can I achive this? (the starting class modification).

我实现了这一点:

<intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

但是当我执行setContentView(R.layout.mynewlayout);时,加载的布​​局是旧布局...

But when I do setContentView(R.layout.mynewlayout); the loaded layout is the old one...

知道为什么会这样吗?

我很愚蠢...新旧布局都一样...现在可以正常工作了.谢谢.

I'm stupid... the old and the new layout were the same... now is working fine. Thank you.

推荐答案

在Android开发中,您实际上并不使用具有main方法的类.实际上,系统的体系结构是完全不同的-每当用户启动申请/交易时,系统就会加载活动".

In Android development you don't actually work with a class that has a main method. In fact, the architecture of the system is quite different - the system loads Activities whenever the user starts an applicaiton/widged.

您需要标识您的主要Activity类-它应该位于项目文件夹中src/some/package/name/YourActivity.java(或类似名称)下.不过,您已经了解了Activity的工作方式,以及如何通过XML和以编程方式创建和加载用户界面.

You need to identify your main Activity class - it should be in your project folder under src/some/package/name/YourActivity.java (or similar). You have learn how Activities work and how user interfaces are created and loaded both via XML and programmatically, though.

您可以在此处找到有关活动的更多信息: http://developer.android .com/guide/topics/fundamentals/activities.html

You can find more information about Activities here: http://developer.android.com/guide/topics/fundamentals/activities.html

这篇关于如何在Android App中定义主类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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