Inflate layout programmatically within another layout

前端 未结 8 2067
心在旅途
心在旅途 2020-11-30 04:54

I need help with my android app. I need inflate a layout within another layout and I dont know how I do. My xml code is this:

  • item.xml - I need inflate mult

8条回答
  •  难免孤独
    2020-11-30 04:56

    You can implement this like below:

    LayoutInflater linf;
    LinearLayout rr;
    
    linf = (LayoutInflater) getApplicationContext().getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);
    linf = LayoutInflater.from(activity.this);
    
    rr = (LinearLayout) findViewById(R.id.container_destacado);
    
    for (int i = 1; i < NoOfTimes; i++) {
    
        final View v = linf.inflate(R.layout.item, null);
        rr.addView(v);
    }
    

提交回复
热议问题