How to check TextView Visibility using IF

后端 未结 2 1086
既然无缘
既然无缘 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.

    0 讨论(0)
  • 2021-02-06 01:03

    // If TextView is already showing and you want to hide it.

    if (TvFolk1.isShown()) {
        TvFolk2.setVisibility(View.INVISIBLE);
    }
    

    // For uncheck all radio button from radio button groups

    RadioGroup rgButton = (RadioGroup)findViewById(R.id.radiobuttongroup);
    rgButton.clearCheck();
    
    0 讨论(0)
提交回复
热议问题