Reputation: 25
I have a function that when a button is clicked the TextView changes to something different. My issue is that the TextView is changing (I want to eat the apple) but only for a few milliseconds then it changes back to what it was before (I want to eat). Can anyone tell me why this is?
Java File:
public class EatOptions extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eatoptions);
TextView eat = (TextView) findViewById(R.id.eatbanner);
eat.setText("I want to eat");
}
public void apple (View view){
Intent intent = new Intent(this, EatOptions.class);
startActivity(intent);
TextView finalBanner = (TextView) findViewById(R.id.eatbanner);
finalBanner.setText("I want to eat the apple");
}
}
LogCat error each time button is clicked:
07-30 17:44:22.276: W/ResourceType(11368): Failure getting entry for 0x01080a03 (t=7 e=2563) in package 0 (error -75)
Upvotes: 1
Views: 44
Reputation: 157457
It is changing because you are restarting the Activity
every time you click on the button
Remove
Intent intent = new Intent(this, EatOptions.class);
startActivity(intent);
Upvotes: 2