.setEnabled似乎只能切换一次

时间:2012-10-04 07:53:30

标签: android android-view android-button

.setEnabled()似乎只能工作一次吗?我希望在活动生命周期内根据内容多次打开和关闭它。我已经尝试将它包装在switch语句中。

        GAME_STATE_INPLAY = true;       
        if (GAME_STATE_INPLAY = true) {
            explainButton.setEnabled(false);
        }
    ....
        if (c.getString(7).toString().length() > 0) {
                explainButton.setEnabled(true);
        }

1 个答案:

答案 0 :(得分:0)

尝试再次通过id获取btn:

   if (GAME_STATE_INPLAY = true) {
        Button explainButton =(Button) findViewById(R.id.button);
        explainButton.setEnabled(false);
    }

    if (c.getString(7).toString().length() > 0) {
            Button explainButton =(Button) findViewById(R.id.button);
            explainButton.setEnabled(true);
    }
相关问题