How to add another layout number of time to my already created LinerLayout?

家住魔仙堡 提交于 2019-12-04 20:38:35
jeet

Just create a loop like below:

    LinearLayout parent=findViewById(R.id.myLayout);
    for(int i=0;i<list.size();i++)
    {
       LinearLayout llItem=(LinearLayout)LayoutInflater.createFromSource(R.layout.child, null);
       TextView txt= (TextView)llItem.findViewById(R.id.title);
       txt.setText(list.get(i));
       parent.add(llItem);
    }

Inflate the view then add to the parent

LinearLayout parent = (LinearLayout)findViewById(R.id.myLayout);

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Layout child = inflater.inflate(R.layout.myLayout2, null);
TextView title = (TextView)child.findViewById(R.id.list_title);
parent.addView(child);

Repeat as many times as necessary or use a loop

If i understood your question correctly you need to display button, textview and button side by side in your layout. If you want this you just take listview and use custom adapter, with this you can display button, text and button side by side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!