Android programmatically include layout (i.e. without XML)

I met this issue too, and I just solved it now. I think my solution is easier:

  1. create a inflater:

    LayoutInflater inflater = (LayoutInflater)      this.getSystemService(LAYOUT_INFLATER_SERVICE);
    
  2. inflate the child layout:

    View childLayout = inflater.inflate(R.layout.child,
                (ViewGroup) findViewById(R.id.child_id));
    
  3. add it into parent:

    parentLayout.addView(childLayout);
    

It’s done, enjoy it!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)