Created
January 31, 2017 06:52
-
-
Save alfianyusufabdullah/4e9c93b10e94e8740323881e7ca9cc25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.developerrandom.belajarmenghubungkanmactivity; | |
| import android.content.Intent; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.view.View; | |
| import android.widget.Button; | |
| public class MainActivity extends AppCompatActivity { | |
| /// BUAT 3 VARIABEL BUTTON | |
| Button Activity_1; | |
| Button Activity_2; | |
| Button Activity_3; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| /// INISIALISASI VARIABEL BUTTON YANG SUDAH DI BUAT | |
| Activity_1 = (Button) findViewById(R.id.activity_1); | |
| Activity_2 = (Button) findViewById(R.id.activity_2); | |
| Activity_3 = (Button) findViewById(R.id.activity_3); | |
| /// activity_1 dan lainnya adalah id yang kita tambahkan lewat xml activity_main.xml | |
| /// selanjutnya menambahkan event handle pada tiap tiap button | |
| Activity_1.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| // Gunakan intent untuk menghubungkan Activity | |
| Intent pindahActivity1 = new Intent(MainActivity.this, Activity_1.class); | |
| startActivity(pindahActivity1); | |
| } | |
| }); | |
| Activity_2.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Intent pindahActivity2 = new Intent(MainActivity.this, Activity_2.class); | |
| startActivity(pindahActivity2); | |
| } | |
| }); | |
| Activity_3.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Intent pindahActivity3 = new Intent(MainActivity.this, Activity_3.class); | |
| startActivity(pindahActivity3); | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment