How to check TextView Visibility using IF

后端 未结 2 1088
既然无缘
既然无缘 2021-02-06 00:23

I have an onCheckChangedListener to show a textView depending on which radio button is selected. I have 1 question and 1 problem that I was wondering if anyone could help me wi

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-06 00:57

    The View class includes a getVisibility() method. Compare that:

    Eg:

    if (TvFolk1.getVisibility() == View.VISIBLE)
      TvFolk2.setVisibility(View.GONE);
    

    To shorten down code, you can also make a method:

    public static void goneIfVisible (View v)
    {
      if (v.getVisibility() == View.VISIBLE)
          v.setVisibility(View.GONE);
    }
    

    And keep in mind in Java, variables are lowercased, only use uppercase for class names.

提交回复
热议问题