【发布时间】:2017-12-07 16:24:03
【问题描述】:
标题只是一个例子。在我的第一个 Activity 中,我有 2 个按钮。如果您点击第一个Button (Button1),您将访问activity 2.1。但是当您点击第二个Button(Button2) 时,您将访问Activity 2.2。在activity 3 中,有必要知道用户点击了哪个Button(按钮enter code here2 或1),因为它们将显示不同的TextViews。那么如何显示这个不同的TextViews?
此代码位于Activity 3。
public void Button1 (View view) {
TextView txtView = (TextView)findViewById(R.id.nextText);
if (txtView .getVisibility() == View.VISIBLE)
txtView.setVisibility(View.VISIBLE);
else
txtView.setVisibility(View.VISIBLE);
}
public void Button2 (View view) {
TextView txtView = (TextView)findViewById(R.id.nextText2);
if (txtView .getVisibility() == View.VISIBLE)
txtView.setVisibility(View.VISIBLE);
else
txtView.setVisibility(View.VISIBLE);
}
【问题讨论】:
-
将按钮名称发送为
putStringExtra和Intent
标签: java android xml button android-activity