【问题标题】:setVisibility(View.INVISIBLE) not working in onResume() methodsetVisibility(View.INVISIBLE) 在 onResume() 方法中不起作用
【发布时间】:2017-08-13 00:06:25
【问题描述】:

在没有完成 A 的情况下从 Activity A 开始了一个 Activity B。如果 Activity B 完成了,我在 Activity A 的 onResume() 中编写了一个方法来使 ImageView 不可见。但这行不通。代码如下。

public void onResume()
{
    if(preferenceUtil.getMUSIC_ONOFF()==0) {
        try {
            player.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    giftbutton.setEnabled(true);
    giftbutton.setClickable(true);

    checkUnlockedStory();
    super.onResume();
}

  public void checkUnlockedStory()
        {
             if(preferenceUtil.getOVERALL_STARS()>=24)
            {                 
                    giftbutton.setImageResource(R.drawable.gift);
                    giftbutton_count.setVisibility(View.INVISIBLE);                  

            }
   }

【问题讨论】:

  • 你检查过Activity A的onResume()是否在从Activity B返回到Activity A时调用了吗?
  • 尝试调试,很难判断您的“总星数”是否真的 >= 24 并且“if”中的代码被调用。
  • @Sachin Saxena OnResume() of Activity A 在从 Activity B 返回时被调用。同样的代码行 giftbutton_count.setVisibility(View.INVISIBLE);也执行了,但视图仍然可见

标签: android visibility


【解决方案1】:

确保您已覆盖 onResume 方法:

@Override
protected void OnResume()
{
super.onResume();
//Type your code here
}

【讨论】:

    【解决方案2】:

    试试这个

    giftbutton_count.setVisibility(View.GONE);
    

    【讨论】:

    • 虽然此代码可能会回答问题,但提供有关 如何 和/或 为什么 解决问题的附加 context 将改善答案的长度长期价值。提及为什么这个答案比其他答案更合适也没有什么坏处。
    【解决方案3】:

    我认为你使用了错误的 id,可能缺少这个

    giftbutton.setVisibility(View.INVISIBLE);

    【讨论】:

      【解决方案4】:

      对于未来的谷歌员工,您可能需要在yourView.setVisibility(View.GONE); 之后执行yourView.clearAnimation();,因为您的视图可能已经开始动画一次,这会导致额外的图层仍然可见。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多