Jumat, 06 Januari 2017

antar activity eclipse android

Main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Selamat Datang" />
<Button
android:id="@+id/btnpindah"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Target" />
</LinearLayout>

Target xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
> 
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Layout Target"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/btnmain"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Main" />
</LinearLayout>

Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rocky.android.pertemuan5"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true" >
<activity
android:name="rocky.android.pertemuan5.MainActivity"
android:label="@string/app_name" >
<activity android:name="Target"></activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="target"></activity>
</application>
</manifest>

Main activity

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rocky.android.pertemuan5"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true" >
<activity
android:name="rocky.android.pertemuan5.MainActivity"
android:label="@string/app_name" >
<activity android:name="Target"></activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="target"></activity>
</application>
</manifest>





java

package rocky.android.pertemuan5;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class target extends Activity implements OnClickListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.target);
Button move = (Button)findViewById(R.id.btnmain);
move.setOnClickListener(this);
}
public void onClick(View v) {
if(v.getId()==R.id.btnmain) {
Intent i=new Intent(this,MainActivity.class);
startActivity(i);
finish();//menghapus history class ini
}
}

}

Tidak ada komentar:

Posting Komentar