0

I have a parent custom layout (child of LinearLayout) that I inflate programmatically.

In the constructor I add another layout to be a child of my parent layout like this:

public ExtendedContentLinearLayout(Context context) {
    super(context);
    this.context = context;

    this.setClickable(false);

    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mTrigger = inflater.inflate(R.layout.nav_menu_board_expandable_children_outer, this, true);
    mTrigger.setOnClickListener(this);
    mTrigger.setBackgroundResource(R.color.da_blue);


}

The parent layout and the "trigger" layout (The child just added above) are working and shown fine.

Once the user touches this "trigger" layout, I want to add a new child to the parent - another layout with more content and thus I need to parent layout to expand and include the newly added layout but this is not working!

Clicking the trigger layout doesn't add a new layout (At least not shown on screen). This is the click call (the click event is working):

   @Override
    public void onClick(View v) {
        App.disableTouchEventForDefaultDuration();

    Log.d("CLICKED", "CLICKED");


    LinearLayout mContent = new LinearLayout(context);
    mContent.setOrientation(HORIZONTAL);
    mContent.setBackgroundResource(R.color.da_indicator_pink);
    mContent.setVisibility(VISIBLE);
    ExtendedContentLinearLayout.this.addView(mContent);


}
3
  • When you click what exactly happening now ? Does it displaying any error ? Commented Feb 2, 2015 at 10:32
  • No error at all. Just the view not showing. Commented Feb 2, 2015 at 10:35
  • Does the parent layout is set to fixed size or set to wrap content? Commented Feb 2, 2015 at 10:37

3 Answers 3

1

I ended up creating the layout in XML and then inflating it using:

 View view = inflater.inflate(this.layout, null, false);

and then adding this view using addView(view)

this works just fine for me

Sign up to request clarification or add additional context in comments.

Comments

0
mContent.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

Please try above code , try for WRAP_CONTENT as well as MATCH_PARENT

Comments

0

In my case, layout.post worked

ExtendedContentLinearLayout.this.post( new Runnable() {
    @Override
    public void run() {
        ExtendedContentLinearLayout.this.addView(llhItem);
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.