【问题标题】:Button a button unclickabale in AndroidButton Android 中不可点击的按钮
【发布时间】:2014-06-11 07:43:46
【问题描述】:

我正在尝试开发一个测验应用程序,我有一个包含所有级别的主菜单,我希望当一个级别完成后,使其主菜单中的按钮无法点击..

有可能吗?

谢谢

【问题讨论】:

  • button.setEnabled(false);或 button.setOnClickListener(null);
  • 我试过 button.clickable(false);但是什么时候才能知道测验已经完成了......?

标签: android button android-activity


【解决方案1】:

假设你有五个问题。当他到达最后一个问题时。他明确提交或单击下一步。如果它在另一个 Activity 中,则只需在 Intent 中传递一个布尔变量。

Intent intent = new Intent(CurrentActivity.this,Destination.class);

intent.putExtra("flag",true/False);

startActivity(intent); 

在另一个活动中获得意图..

boolean flag = getIntent.getExtra().getBoolean("flag");

if(flag)
//  button.setEnabled(false);

else 

// do other stuff

// 发送和接收布尔值

额外设置意图:

Intent intent = new Intent(this, NextActivity.class);
intent.putExtras("yourBoolName", true);

额外检索意图:

@Override
protected void onCreate(Bundle savedInstanceState) {
    Boolean yourBool = getIntent().getExtras().getBoolean("yourBoolName");
}

【讨论】:

  • 获取另一个活动的意图不起作用。
  • 对不起,我忘记添加 getBoolean.. 现在查看编辑。
【解决方案2】:

在此方法集中定义的按钮对象中尝试此代码

按钮按钮 = (Button) findViewById(R.id.button1); button.setEnabled(false);

【讨论】:

    猜你喜欢
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多