Two Activity (memanggil dua Aktifitas Class) (Android)

Class Pertama

package Main.Aerdy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Child extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.child);

TextView txtChild = (TextView)findViewById(R.id.child_txtPage);
Button go = (Button)findViewById(R.id.child_btnPage);
Intent i = this.getIntent();

txtChild.setText(“This is child “+i.getStringExtra(“pesan”));
go.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

finish();

}

});

}
}

Class Ke dua

package Main.Aerdy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button go =(Button)findViewById(R.id.main_btnPage);
go.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this, Child.class);
i.putExtra(“pesan”, “From Activity Main”);
startActivity(i);

}
});
}
}

Download project nya di sini

Advertisements

Published by

jarcode

hello I am jarcode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s