Dynamically change the look of the internal view in Android

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

The blue part is the place where I want to upload various Views. 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 in the blue part?

+3
source share
2 answers

I 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 on top of the body part (blue part of the image)

I declared the body as follows:

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

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

This is sais java.lang.IndexOutOfBoundsException: index=1 count=0

How can i fix this?

Edit: it turned out:

body.addView(layoutInflater.inflate(R.layout.gegevens_verzekeringen, null));
+5
source
  • findViewById, RadioButton
  • OnClickListener setOnClickListener RadioButton
  • OnClickListener
0

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


All Articles