How to define the main class in an Android App?
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).
[EDIT]
I achieve this adding to my manifest this:
<intent-filter>
<action android:name="android.intent.action.MAI开发者_运维问答N" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
But when I do setContentView(R.layout.mynewlayout);
the loaded layout is the old one...
Any idea why is this happening?
[EDIT2]
I'm stupid... the old and the new layout were the same... now is working fine. Thank you.
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.
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.
You can find more information about Activities here: http://developer.android.com/guide/topics/fundamentals/activities.html
modify the main class of the application to start with another layout.
To be able to do this, in the onCreate method, you decide on the layout by with the following:
setContentView(R.id.layout_id)
layout_id is the name of your layout xml file.
I want to create a new class with his layout
If i understand it correctly, you should copy the layout xml file in his project, in the layout folder, into your own layout folder and using the above method, you can use his layout.
You sould take a look at the Android tutorials to get a better grasp of this concept.
tell me what the logCat says??
an according to you that android can't show your new layout in main.xml to me so that just i tell you more about it.
Create a new Activity, opposed to changing the original and then open up AndroidManifest.xml and change the single android:name line from the original Activity to the newly created name.
<activity android:name="NewActivity" // Used to be OldActivity
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
精彩评论