+ 1

What is the java code and manifest code

What is the java code to start a new activity? like, using a button. Im stack in this code. the intent.I have sub.xml for the new activity layout ang SubActivity.java. the button id is button1. also in the manifest.xml i added new activity with label on it, theme ang name=".SubActivity" startActivity()

20th Feb 2017, 7:39 AM
Ken Malinao
Ken Malinao - avatar
3 odpowiedzi
+ 1
MainActivity.java Yourbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), SubActivity.class); startActivity(intent); } }); AndroidManifest.xml <activity android:name=".MainActivity" android:label="Hello World> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:label="Sub Activity" android:name=".SubActivity"/>
20th Feb 2017, 7:52 AM
Patolia Vishal
Patolia Vishal - avatar
0
Thanks you for your answer. I will try that later.
20th Feb 2017, 9:11 AM
Ken Malinao
Ken Malinao - avatar
0
I thought the new <activity in manifest will be below the first <activity.
20th Feb 2017, 9:13 AM
Ken Malinao
Ken Malinao - avatar