RadioGroup, setEnabled (false) doesn't work!

I used setEnabled (false) to set it inactive, but it does not work. and after this method, the value of RadioGroup.IsEnabled () is false. The value has been changed.

The code is in the Android programming guide. Ps: Spinner component uses setEnabled (false).

as follows:

package com.example.testviews;

import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.RadioGroup; public class TestRadioGroup extends Activity { @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.radiogroup); final RadioGroup testRadioGroup = (RadioGroup) findViewById(R.id.testRadioGroup); final Button changeEnabledButton = (Button) findViewById(R.id.changeEnabledButton); changeEnabledButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub changeEnabled(testRadioGroup); } }); final Button changeBgColorButton = (Button) findViewById(R.id.changeBackgroundColorButton); changeBgColorButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub changeBgColor(testRadioGroup); } }); } protected void changeBgColor(RadioGroup testRadioGroup) { // TODO Auto-generated method stub testRadioGroup.setBackgroundColor(Color.BLUE); } protected void changeEnabled(RadioGroup testRadioGroup) { // TODO Auto-generated method stub if (testRadioGroup.isEnabled()) { testRadioGroup.setEnabled(false); } else { testRadioGroup.setEnabled(true); } } 

}

+23
source share
3 answers

use the following method:

 for (int i = 0; i < testRadioGroup.getChildCount(); i++) { testRadioGroup.getChildAt(i).setEnabled(false); } 
+64
source

Presentations can be made up of several touching elements. You must disable them all, for example:

 for(View lol : your_spinner.getTouchables() ) { lol.setEnabled(false); } 

If it is simple, as it also returns itself:

Find and return all tangible representations that are descendants of this representation, possibly including this representation if it is tangible.

View # getTouchables ()

+3
source

You cannot use the following code:

 for(View lol : your_spinner.getTouchables() ) { lol.setEnabled(false); } 

After views are disabled, there are no more tangible child / descentant views.

0
source

Source: https://habr.com/ru/post/947649/


All Articles