【问题标题】:in android how to make a generic activity i.e different views for next activity for different buttons在android中如何进行通用活动,即不同按钮的下一个活动的不同视图
【发布时间】:2012-02-23 12:14:08
【问题描述】:

我有一个活动选择,它有四个按钮和其他活动结果。现在我想实现这样的逻辑,如果按下 button1,那么它应该在 Result 活动中显示一个 EditText 和一个 TextView,但是如果按下 button2,那么它应该显示 3 个 TextView。 换句话说,我想为不同的按钮点击调用具有不同视图的结果活动。 请帮助我,我是android开发的新手。 提前致谢。

【问题讨论】:

标签: android android-activity navigation views


【解决方案1】:

从 Select 开始,您必须使用额外的参数来启动 Result,如下所示:

Intent intent = new Intent(this,Result.class);

intent.putExtra("STYLE",1); //1 means you pressed the first button, 2 means second button etc.

startActivity(intent);

在 Result 中,你必须在 onCreate 中得到这个额外的

int extra = getIntent().getIntExtra("STYLE",0);

并动态构建布局:

if(extra == 1)

{

// build style one

} else if(extra == 2) { ... } ...

【讨论】:

  • 我才意识到ntc之前回答了这个问题:我
  • 但你的答案是更好的版本:)
猜你喜欢
  • 1970-01-01
  • 2017-01-04
  • 1970-01-01
  • 1970-01-01
  • 2017-12-10
  • 1970-01-01
  • 2017-07-30
  • 2020-08-01
  • 1970-01-01
相关资源
最近更新 更多