Как сделать чтобы данные layout менялись(текст, картинки) при нажатии на button/imageView? Для каждого персонажа нужно много layout,activity нужно как-то минимизировать код...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agillity);
toolbar=findViewById(R.id.myToolBar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
imageAntimag = (ImageView) findViewById(R.id.imageAntimag);
imageAntimag.setOnClickListener(this);
}
public boolean onSupportNavigateUp(){
onBackPressed();
return true;
}
@Override
public void onBackPressed(){
Intent intent = new Intent(this, ActivityHeroes.class);
startActivity(intent);
finish();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.imageAntimag:
Intent intent = new Intent(this, ActivityHero.class);
startActivity(intent);
// TODO Call second activity
break;
default:
break;
}
}
герой
public class ActivityHero extends AppCompatActivity implements View.OnClickListener {
private Toolbar toolbar;
Button btnAllies;
Button pick;
Button button_sborka;
ImageView tallents;
ImageView aganim;
ImageView shard;
View skill1;
View skill2;
View skill3;
View skill4;
Dialog dialogAganim;
Dialog dialogShard;
Dialog dialogTalletns;
Dialog dialogSpell1;
Dialog dialogSpell2;
Dialog dialogSpell3;
Dialog dialogSpell4;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hero);
toolbar=findViewById(R.id.myToolBar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
btnAllies = (Button) findViewById(R.id.btnAllies);
btnAllies.setOnClickListener(this);
pick = (Button) findViewById(R.id.button_pick);
pick.setOnClickListener(this);
button_sborka = (Button) findViewById(R.id.button_sborka);
button_sborka.setOnClickListener(this);
tallents = (ImageView) findViewById(R.id.tallents);
tallents.setOnClickListener(this);
aganim = (ImageView) findViewById(R.id.aganim_button);
aganim.setOnClickListener(this);
shard = (ImageView) findViewById(R.id.shard);
shard.setOnClickListener(this);
skill1 = (View) findViewById(R.id.viewSkill1);
skill1.setOnClickListener(this);
skill2 = (View) findViewById(R.id.viewSkill2);
skill2.setOnClickListener(this);
skill3 = (View) findViewById(R.id.viewSkill3);
skill3.setOnClickListener(this);
skill4 = (View) findViewById(R.id.viewSkill4);
skill4.setOnClickListener(this);
dialogAganim = new Dialog(this);
dialogShard = new Dialog(this);
dialogTalletns = new Dialog(this);
dialogSpell1 = new Dialog(this);
dialogSpell2 = new Dialog(this);
dialogSpell3 = new Dialog(this);
dialogSpell4 = new Dialog(this);
}
@Override
public void onBackPressed(){
Intent intent = new Intent(this, ActivityAgillity.class);
startActivity(intent);
finish();
}
@Override
protected void onPause() {
super.onPause();
overridePendingTransition(0, 0);
}
public boolean onSupportNavigateUp(){
onBackPressed();
return true;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnAllies:
Intent intent = new Intent(this, ActivityAllies.class);
startActivity(intent);
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.button_pick:
Intent intent = new Intent(this, ActivityContrPick.class);
startActivity(intent);
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.button_sborka:
Intent intent = new Intent(this, ActivitySborka.class);
startActivity(intent);
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.button_sborka:
Intent intent = new Intent(this, ActivitySborka.class);
startActivity(intent);
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.aganim_button:
aganim();
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.shard:
shard();
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.shard:
shard();
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.tallents:
talletns();
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.viewSkill1:
dialogSpell1();
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.viewSkill2:
dialogSpell2();
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.viewSkill3:
dialogSpell3();
// TODO Call second activity
break;
default:
break;
}
switch (v.getId()) {
case R.id.viewSkill4:
dialogSpell4();
// TODO Call second activity
break;
default:
break;
}
}
private void aganim (){
dialogAganim.setContentView(R.layout.dialog_aganim);
dialogAganim.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogAganim.show();
}
private void shard (){
dialogShard.setContentView(R.layout.dialog_shard);
dialogShard.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogShard.show();
}
private void talletns (){
dialogTalletns.setContentView(R.layout.dialog_talents);
dialogTalletns.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogTalletns.show();
}
private void dialogSpell1 (){
dialogSpell1.setContentView(R.layout.dialog_ability1);
dialogSpell1.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogSpell1.show();
}
private void dialogSpell2 (){
dialogSpell2.setContentView(R.layout.dialog_ability2);
dialogSpell2.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogSpell2.show();
}
private void dialogSpell3(){
dialogSpell3.setContentView(R.layout.dialog_ability3);
dialogSpell3.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogSpell3.show();
}
private void dialogSpell4 (){
dialogSpell4.setContentView(R.layout.dialog_ability4);
dialogSpell4.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogSpell4.show();
}
}