TextView会在短时间内发生变化,然后再更改

时间:2014-07-30 16:52:03

标签: android button textview

我有一个功能,当单击一个按钮时,TextView会变为不同的东西。我的问题是TextView正在改变(我想要吃苹果),但只有几毫秒,然后它变回原来的状态(我想吃)。谁能告诉我为什么会这样?

Java文件:

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错误:

07-30 17:44:22.276: W/ResourceType(11368): Failure getting entry for 0x01080a03 (t=7 e=2563) in package 0 (error -75)

1 个答案:

答案 0 :(得分:2)

它正在改变,因为每次单击按钮

时都会重新启动Activity

删除

 Intent intent = new Intent(this, EatOptions.class);
 startActivity(intent);