简体   繁体   English

如何处理动态膨胀的布局内容(多次膨胀相同的布局)

[英]How to handle dynamically inflated layout content (Same Layout inflated multiple times)

I have a Linear layout and inside which there are few dropdown and text views,now i want to inflate the layout each time on click of "add more" button, below is the code for inflating the layout. 我有一个线性布局,里面有一些下拉菜单和文本视图,现在我想在每次单击“添加更多”按钮时都对布局进行充气,下面是对布局进行充气的代码。 the problem i am facing is to assign the id to each inflated layout content .Inorder to handle the content the inlfated layout i need the unique id for each content for each time i am inflating the layout. 我面临的问题是将ID分配给每个膨胀的布局内容。为了处理内容,膨胀的布局我需要在每次膨胀布局时为每个内容使用唯一的ID。

LayoutInflater inflater = (LayoutInflater)   getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row_view;
row_view = (View)inflater.inflate(R.layout.inflatefloor,null);
                inflatefloordetails.addView(row_view);

here inflatefloor is the layout to inflate and inflatefloordetails is the main root layout inside which layout is to be inflated and i am inflating the inflatefloor layout each time on button click. 这里,inflatefloor是要膨胀的布局,inflatefloordetails是要在其中膨胀布局的主要根目录布局,每次单击按钮时,我都会膨胀inflatefloor布局。

New to android pardon if anyone finds the question silly. android赦免的新手,如果有人发现这个问题很傻。

Note:Check out link below if anyone is facing similar problem, I found this link useful. 注意:如果有人遇到类似问题,请查看下面的链接,我发现此链接很有用。

How to set Id of dynamic created layout? 如何设置动态创建版式的ID?

I think it will be helpful. 我认为这会有所帮助。

you can put any object when set the tag to be unique: 您可以在将标记设置为唯一时放置任何对象:

yourView.setTag(Object object);

and to retrive it: 并检索它:

object.indexOf(yourView.getTag())

Otherwise you have to use custom view. 否则,您必须使用自定义视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM