如何在Android中添加第二个活动

Tan*_*r.R 17 android android-intent android-activity

嘿大家!我试图在我的android项目中添加第二个活动,但我不确定如何准确添加活动文件?

我在这里添加了一个类"Name/Scr/PackageName/MyClassHere",但我不确定是否正确的做或放置它,因为也没有XML文件.

我使用此代码打开一个新的屏幕,http://learnandroid.blogspot.com/2008/01/opening-new-screen-in-android.html我得到2个错误.1在运行时这一行: Intent i = new Intent(Coinparison.this, ResultsScreen.class); 它说它无法找到我的活动.

而这里的另一个错误setContentView(R.layout.ResultsScreen);是"ResultsScreen"无法解决.

不确定什么是错的,但任何帮助都很棒!:)

Dam*_*ith 29

现在eclipse中有一个向导用于添加活动,只需右键单击你的项目,转到新的 - >其他 - > android - > Android Activity

这将创建类,布局和清单条目.


小智 17

将您的活动添加到AndroidManifest.xml

<activity android:name="ResultsScreen"
   android:label="@string/app_name">
   <intent-filter>
       <action android:name="android.intent.action.VIEW" />
   </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)