{ Berbagi, Menulis, Dan Mengajar } Ilmu… » 7. Operating System » Multiple Activity on Android Studio Button
Multiple Activity on Android Studio Button
package id.co.ikc.www.starsrunway; 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 { private Button button1, button2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //setContentView(R.layout.activity_login); Button button1 = (Button) findViewById(R.id.button); Button button2 = (Button) findViewById(R.id.button2); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openActivity2(); //openActivity3(); } }); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openActivity3(); } }); } public void openActivity2(){ Intent intent = new Intent(this, Main2Activity.class); startActivity(intent); } public void openActivity3(){ Intent intent = new Intent(this, Main3Activity.class); startActivity(intent); } } //klik.OnClickListener(new view.on)
Filed under: 7. Operating System