I have a method to change a variable (declared =0) into an integer (eg: 10), then I would like to assign this integer to another variable (int playerOneIcon)
SomeActivity
:
public class SomeActivity extends AppCompatActivity implements View.OnClickListener {
Integer playerOneIcon= 0, playerIcon = 0;
onCreate(Bundle savedInstanceState) {
Button btn_test = findViewById(R.id.btn_test);
btn_test.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(ii_PlayerSetting.this, String.valueOf(playerOneIcon), Toast.LENGTH_SHORT).show();
}
});
}
ShowPop1(View v) { }
//Will paste it below
ShowPop2(View v) { }
//Will paste it below
public void onClick(View v){ }
//Will paste it below
}
The "ShowPop1(View v) will run when user clicked on a button, it will call a pop up dialog, hence calling the onClick() within:
ShowPop1(View v)
ShowPop1(View v) {
playerIcon = playerOneIcon;
ChangeHeadDialog.setContentView(R.layout.somelayout);
onClick(v);
playerOneIcon = playerIcon;
}
ShowPop2(View v)
ShowPop2(View v) {
playerIcon = playerTwoIcon;
ChangeHeadDialog.setContentView(R.layout.somelayout);
onClick(v);
playerTwoIcon = playerIcon;
}
onClick(v)
onClick(v){
playerIcon = 10;
ChangeHeadDialog.dismiss();
//if i put "playerOneIcon = playerIcon;" here, it will work, but I can't since it may be playerTwoIcon that should assign instead
}
Then when I pressed the btn_test, result is 0,. Please help, thanks you so much!