【问题标题】:How to accept an int in a another activity & use if statement如何在另一个活动中接受 int 并使用 if 语句
【发布时间】:2014-09-29 03:01:01
【问题描述】:

这基本上就是我现在的情况 (查看链接) Getting RadioButton cannot be resolved to a type

我有一个整数存储单选按钮的值 - 但是,我不知道如何在其他活动中接受它。 这是我目前所拥有的(但我得到一个错误)

Intent i = getIntent();
int value = intent.getIntExtra("inputValue", a);
    if(a = 1)
    {
        //Enter action
    }

【问题讨论】:

  • 我的错误是“a 无法解析为变量”
  • a 应该是默认值的参数。当意图不包含任何带有该键的额外内容时,只需将您想要获得的数字放在那里。如果你想将检索到的值与 1 进行比较,那么你必须这样做:if(value == 1) { ...

标签: android


【解决方案1】:

在 if 条件中使用 value 来检查之前 Activity 中的 inputValue

int value = intent.getIntExtra("inputValue", 0);
if(value == 1) {
    //Enter action
}

如果在意图中未找到密钥,Intent.getIntExtra 也将第一个参数作为 key,将第二个参数作为 default value an int

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    相关资源
    最近更新 更多