开发者

Android Eclipse Add New Activity

I am using Win 7.0, Eclipse and android SDK. I want to add new activity in AndroidManifest.xml Application tab as it is shown in this tutorial Android Development – Adding Screens & Button Handlers

I add an Activity name to my manifest but it does not automatically turn it into a link. e.g. I cannot click开发者_运维知识库 the "Name"(It is not a hyperlink as shown in the article), thus I cannot create my class.

Can You Help me? what is the problem ?


1.Go to the Androidmanifest.xml file and add the activity inside the tag if your activity name is secondAct.

2.Create a class named secondAct.

<application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Project1Activity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".secondAct"></activity>
        <activity android:name=".third"></activity>
    </application>

3 . if you are using a button for going to next activity, use the following code in secondAct.java

Button fbtn=(Button)findViewById(R.id.sbtn);
        fbtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent sec=new Intent(secondAct.this,com.asish.third.class);
                startActivity(sec);

            }
        });


Go to the small tab underneath that says AndroidManifest.xml and shows you the XML code for it. It should look like this:

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name=".ApplicationName"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".AnotherActivity"></activity>

</application>

Okay, click on ADD, then select the top box that says "Create a new element at the top level, in Application" and then you should get a box with linkable NAME*.


You need to create the class first, then point to that class in your manifest... just putting the class name in the manifest is not enough. It will not automatically create it for you.

Also, it is easier to create the class first because then Eclipse will autocomplete the class name/path for you.

EDIT: AH HAH! I see what link you are talking about... Yeah, you need to actually create the class first for that to appear.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜