开发者

How To Add Second Activity In Android

开发者 https://www.devze.com 2023-03-10 23:33 出处:网络
Hey everyone! Im trying to add a second activity to my android project, but im not sure how to add t开发者_开发百科he activity files exactly?

Hey everyone! Im trying to add a second activity to my android project, but im not sure how to add t开发者_开发百科he activity files exactly?

Ive added a class here "Name/Scr/PackageName/MyClassHere" but Im not sure if that the correct thing to do or place to put it, because there isnt a XML file either.

Im using this code to open a new screen, http://learnandroid.blogspot.com/2008/01/opening-new-screen-in-android.html And I get 2 error's. 1 at runtimeon this line: Intent i = new Intent(Coinparison.this, ResultsScreen.class); it says it cant find my activity.

And the other error here setContentView(R.layout.ResultsScreen); which says "ResultsScreen" cannot be resolved.

Not sure whats wrong, but any help is great! :)


There is a wizard in eclipse now for adding activities, just right click on your project, go to new -> other -> android -> Android Activity

This will create the class, layout and manifest entry.


Add your activity to AndroidManifest.xml

<activity android:name="ResultsScreen"
   android:label="@string/app_name">
   <intent-filter>
       <action android:name="android.intent.action.VIEW" />
   </intent-filter>
</activity>


i think u need add this activity in manifest file like this

 <application  balblabla>
        <activity android:name=".firstActivity">
                  android:label="@string/app_name"
             //bla bla bla
        </activity>
    <activity android:name=".secondActivity"/>

    </application>

see link again and find this : //AndroidManifest.xml there u can see text which writed in bold mode

<activity class=".Screen2" android:label="Screen 2">
      </activity>


Answer for Error in """ setContentView(R.layout.ResultsScreen); which says "ResultsScreen" cannot be resolved """

Go to second.java (Related to second activity) file and import missing classes.

In Eclipse, press Ctrl + Shift + O to import missing classes (Cmd + Shift + O on Mac).

0

精彩评论

暂无评论...
验证码 换一张
取 消