Invisible radiobutton with spinner

Asked

Viewed 236 times

1

I would like to know how to make the event change of a spinner it leaves visible or invisible a radiobutton. I have the following code. But it’s not working.

 <RadioGroup 
                       android:id="@+id/radioGrupo"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:visibility="invisible"
                        android:orientation="horizontal">

                        <RadioButton
                            android:id="@+id/radioUsuario"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:visibility="invisible"
                            android:onClick="onRadioButtonClicked"
                            android:text="Usuário" />

                        <RadioButton
                            android:id="@+id/radioNaoUsuario"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:onClick="onRadioButtonClicked"
                            android:visibility="invisible"
                            android:text="Não usuário" />

                    </RadioGroup> 

private void ExibeUsuarioNaoUsuario()
{
    naoUsuario =(RadioButton) findViewById(R.id.radioNaoUsuario);
    usuario =(RadioButton) findViewById(R.id.radioUsuario);
    groupUsuarioNaoUsuario =(RadioGroup)findViewById(R.id.radioGrupo);
    spnTipoCliente = (Spinner)findViewById(R.id.spnTipoCliente);
    spnTipoCliente.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {

            groupUsuarioNaoUsuario.setVisibility(RadioGroup.VISIBLE);
            //usuario.setVisibility(RadioButton.VISIBLE);
            //naoUsuario.setVisibility(RadioButton.VISIBLE);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
            usuario.setVisibility(RadioButton.INVISIBLE);
            naoUsuario.setVisibility(RadioButton.INVISIBLE);
        }

    });

}
  • How do you know the code doesn’t work? Are you sure that the onItemSelected isn’t being called? Or are the buttons not invisible? Hiding the RadioGroup and the RadioButton doesn’t work?

  • @Wakim tried to make invisible only the radiogroup or only the radiobuttons but it did not work. When I change the spinner item it does not make them visibel even I passing the setvisibilty. And this being called yes certainly.

  • I’ll test your code here and see if I can reproduce the problem.

1 answer

2


Use setVisibility(View.INVISIBLE) works in the RadioGroup, is even better than setting visibility for all RadioButton's.

The problem is understanding about the onNothingSelected.

I didn’t really know it until now, but it’s practically not called when the user touches on the Spinner, yes when the user’s previous selection ceases to exist.

Callback method to be Invoked when the Selection disappears from this view. The Selection can disappear for instance when touch is Activated or when the Adapter Becomes Empty.

This can be seen, when you clean the Adapter with some option previously selected.

If your logic is to hide when a particular item is selected, perhaps the best solution is to check the parameter position or even the label if it’s something safer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.