Reputation: 61
I want to change the text on a button when onResume() is called, (the setText its working because if I do a Toast it shows me the text I want but the button has the old string).
@Override
public void onResume() {
super.onResume();
if(ban == 0) {
reDraw();
fillInfo();
SharedPreferences sharedPreferences = getSharedPreferences("layoutRequestData", Context.MODE_PRIVATE);
getFlagSendBill = sharedPreferences.getBoolean("flagSendBill", false);//comenzar servicio
if(getFlagSendBill == true) {
View view = LayoutInflater.from(this).inflate(R.layout.request,null);
buttonBService = (Button) view.findViewById(R.id.buttonBeginService);
//buttonBService = (Button) findViewById(R.id.buttonBeginService);
buttonBService.setText("Ver Recibo");
Toast.makeText(this,"LALALA" + buttonBService.getText(),Toast.LENGTH_SHORT).show();
}
else{
// buttonBService = (Button) findViewById(R.id.buttonBeginService);
//buttonBService.setText("Comenzar Servicio");
}
}
}
My buttonBService and my getFlagSendBill are public
Upvotes: 0
Views: 499
Reputation: 48258
You are overwriting the hole button, take a look at the Activity lifecycle,
the good practice is that you initialize the button in the onCreate
method, then assign any value in the onResume
, the same applies to the view....
Upvotes: 0
Reputation: 93569
Why are you inflating a new layout? You should be changing the text on the existing layout. By inflating a new one and not setting it as the context view you're changing the text on a button that isn't ever on screen.
Upvotes: 2