In these video i will tell you how to create button in android studio to change activity.
1)First create two buttons in activitymain.xml,name two buttons as button and button 2 and change constraint layout into relative Layout.
2)Then create two activities name as button1 and button 2.
3)Create same Textviews into two Activities .
4)In button1Activity.Java and button2Activity.Java create same Textviews and initialise it.
5)Then add below code above Override
Button button;
6)Add code below
{ setContentView(R.layout.activity_main); }
Code which is to be paste is
final Button button1=(Button)findViewById(R.id.button1);
Button button2=(Button)findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent int2=new Intent(MainActivity.this,button1.class);
startActivity(int2);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent int2=new Intent(MainActivity.this,button2.class);
startActivity(int2);
}
});
}
}
7) At last don't forget to remove last two brackets.
Thanks for watching, please like share and subscribe to my channel..