Cara pindah Layout Dengan Intent yaitu dengan menyetel 2 file
-ActivityMain.java
-AndroidManifest.xml
Pertama Buat File
ActivityMain.java
Isikan Kode ini
package com.mycompany.myapp;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.mycompany.myapp.R;
import android.app.*;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);{
//EditText
Button btnCall = (Button) findViewById(R.id.button1);
//ketika menekan tombol call
btnCall.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,Activity2.class);
startActivity(intent);}});}}}
Activity2.java
Isikan kode ini
package com.mycompany.myapp;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.mycompany.myapp.R;
import android.app.*;
public class Activity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maindua);{
//EditText
Button btnCall = (Button) findViewById(R.id.button1);
//ketika menekan tombol call
btnCall.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Activity2.this,MainActivity.class);
startActivity(intent);}});}}}
AndroidManifest.xml
Isikan Kode Ini
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".MainActivity"
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=".Activity2"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Untuk tampilannya sesuakan saja dengan Id tombol yang ada di file java
Untuk AndroidManifest di bagian android:name
Isikan dengan nama file Java