-1

I need an xml file for the following: I have a check box button. When I click it 3 more check boxes buttons will apprear on the screen. How to do that ?

1
  • Stack Overflow is not "teach me how to program " site .. please read the rules detailed in faq, thanks
    – Moog
    Apr 20, 2012 at 9:50

3 Answers 3

2

Just add all the checkboxes to the layout, so they are all visible, and then use code like this to make some visible/invisible dynamically:

findViewById(R.id.checkbox5).setVisibility(View.VISIBLE)

findViewById(R.id.checkbox5).setVisibility(View.GONE)

You can set the default visibility using android:visibility="gone" in the XML

2
  • thx for reply. How to change the dimensions of the 3 children check boxes smaller than the parent? Apr 20, 2012 at 9:14
  • Best to post new questions for further issues. UI Views in Android are done with bitmaps, some stretch but some will not. You can try using layout_height and layout_width to set the size, but I expect that with checkboxes it will not work (as it does for a TextView), and you will need to provide your own (smaller) image set, using a drawable <selector> (to specify which image to use for selected, and unselected)
    – Ollie C
    Apr 20, 2012 at 9:17
2

Depends on how you do it. You could add the three extra check boxes in your layout file and then set them invisible until the right check box is checked.

0

You can make gone to visible your new checkboxes.

or

You can inflate new checkboxes and add to the desired layout.

like below is the code to add multiple images

p

rivate LayoutInflater  inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

                            circleLinearLayout.removeAllViews();

                while (circlesNeedToDisplay > 0) {
                    ImageView imageView = (ImageView) inflater.inflate(
                            R.layout.circle_item, null);
                    circleLinearLayout.addView(imageView);
                    circles.add(imageView);
                    circlesNeedToDisplay--;
                }

xml code for R.layout.circle_item

<?xml version="1.0" encoding="utf-8"?>
<ImageView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:paddingTop="10dip"
        android:background="@drawable/circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

By using the same procedure you can add check boxes as well.

Not the answer you're looking for? Browse other questions tagged or ask your own question.