Inflate layout programmatically within another layout

前端 未结 8 2066
心在旅途
心在旅途 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 05:02

    ll = (LinearLayout) findViewById(R.id.container_destacado);  // ll is the layout where your inflated layout will be added 
    linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    int pos = 0;
        while (pos < noOfTimes) 
        {
            View myView = linflater.inflate(R.layout.item, null); //here item is the the layout you want to inflate 
            myView.setId(pos);
            /*
               You can change TextView text and ImageView images here e.g.
               TextView tv = (TextView)myView.findViewById(R.id.title_N1);
               tv.setText(pos);
    
            */
            pos++;
            ll.addView(myView);
        }
    

提交回复
热议问题