开发者

Setting the time on a button in a different Activity in Android

开发者 https://www.devze.com 2023-03-01 05:40 出处:网络
In my application I have two activities.In the first acti开发者_开发技巧vity I have a button, and in the second activity I have another button.My problem is, when the user presses the first button I w

In my application I have two activities. In the first acti开发者_开发技巧vity I have a button, and in the second activity I have another button. My problem is, when the user presses the first button I want to set the time display on the second button in the second activity. Can any one help me with a solution?


Pass the value of one button to the second activity:

String text = button.getText();
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("time", text);

in second activity:

Intent intent = getIntent();
if (intent.getExtras() != null) {
  String time = intent.getExtras().getString("time");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消