Activity1.java
package cem.examples.activityswitch;
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 Activity1 extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);this.setContentView(R.layout.main);
// ------------------------------------------------------
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent myint = new Intent(v.getContext(),Activity2.class);
startActivityForResult(myint, 0);
}
}
Activity2.java
package cem.examples.activityswitch;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
public class Activity2 extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activite2);
// --------------------------------------------------------------
Button btnPre = new Button(this);
btnPre.setText("Geriiiii");
// Butonun layout üzerinde alacağı görünüm parametreleri
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
// --------------------------------------------------------------
LinearLayout layout = (LinearLayout) findViewById(R.id.lout);
layout.addView(btnPre, params);
// --------------------------------------------------------------
// Önceki aktiviteye gidelim.
btnPre.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// Call this to set the result that your activity will return to its caller.
setResult(RESULT_OK);
// Call this when your activity is done and should be closed
finish();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cem.examples.activityswitch" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Activity1" android:label="Activite Etiketi"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2"></activity>
</application>
</manifest>
Hiç yorum yok:
Yorum Gönder