Dynamically change view inside view in Android

前端 未结 2 1046
清酒与你
清酒与你 2020-12-18 12:03

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 pl

相关标签:
2条回答
  • 2020-12-18 12:38
    • use findViewById to get a reference to each RadioButton
    • Register an OnClickListener using setOnClickListener on each RadioButton
    • Inside your OnClickListener callback, load a different background
    0 讨论(0)
  • 2020-12-18 12:52

    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));
    
    0 讨论(0)
提交回复
热议问题