Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change view inside view in Android

I have this RelativeView with 3 radiobuttons on top. I want to change the bottom part of the view when the user clicks on one of the buttons.

The blue part is the place i want to load different Views in. alt text

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    if (checkedId == iVerzekeringen){
        layout.removeView(body);   // THIS PART IS
        layout.addView(testview);  // NOT WORKING
    }
    else if (checkedId == iPersoonlijk){
    }
    else if (checkedId == iNotities){
    }
}

How can i load different Views into the blue part?

like image 417
Galip Avatar asked Nov 20 '25 20:11

Galip


1 Answers

I kinda found the answer:

layout = (RelativeLayout)findViewById(R.id.rellayout);
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
layout.addView(layoutInflater.inflate(R.layout.gegevens_verzekeringen, group, false), 1 );

This loads the view over the parent xml. I want it to load it over just the 'body' part (the blue part in the picture)

I declared the body like this:

body = (RelativeLayout)findViewById(R.id.body);

But when i do body.addView(layoutInflater.inflate(R.layout.gegevens_verzekeringen, group, false), 1);

It sais java.lang.IndexOutOfBoundsException: index=1 count=0

How can i fix this?

Edit: Got it:

body.addView(layoutInflater.inflate(R.layout.gegevens_verzekeringen, null));
like image 50
Galip Avatar answered Nov 23 '25 10:11

Galip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!