views:

48

answers:

2

How can I have a checkbox in my ui alter my ui live? For example, if the box is unchecked I want a spinner to be displayed, and if the box is checked I want a text box to be displayed in place of the spinner. I know how to create the checkbox and check its status but I don't know how to hide and reveal other elements in an activity.

+1  A: 

You need to register an OnClickListener for the checkbox.

http://developer.android.com/reference/android/view/View.OnClickListener.html

cosgrove
+1  A: 

If you add your switchable layout inside a LinearLayout or RelativeLayout or similiar, you can easily toggle the visibility.

LinearLayout ll = (LinearLayout) findViewById(R.id.myLinearLayout);
ll.setVisibility(View.GONE);

In you XML you should set the attribute android:visibility="gone" and change it at runtime.

WarrenFaith