Android的 - 动态添加片段片段、动态、Android

由网友(时光予我孤独)分享简介:我已经看过了互联网附近,我发现Android的片段(fragments),在那里它们被放置在位置(像他们两个,一个作为一个列表,二是从列表diplaying所选项目的详细信息)的唯一例子。我的目标是有经典的Andr​​oid的活动,我希望能够加入到其动态$特别GUI p $ p型$ P ​​$ ppared片段。我想补...

我已经看过了互联网附近,我发现Android的片段(fragments),在那里它们被放置在位置(像他们两个,一个作为一个列表,二是从列表diplaying所选项目的详细信息)的唯一例子。我的目标是有经典的Andr​​oid的活动,我希望能够加入到其动态$特别GUI p $ p型$ P ​​$ ppared片段。我想补充有圆顶的EditText元素(editTextFragment),或几个单选按钮(r​​adionbuttonFragment)的组。是否有如何做到这一点的任何例子吗?制造稳定的片段是无法使用我。

I have looked around the internet and I have found only examples of Android fragmens, where they are placed on place (like two of them, one as a list, second is diplaying details of a selected item from list). My goal is to have classic android activity and I want to be able to add to it dynamically pre-prepared fragments with particular GUI. I want to add there dome group of EditText elements (editTextFragment), or several radiobuttons (radionbuttonFragment). Is there any example of how to do that? Making stable fragments is not usable for me.

感谢

推荐答案

这答案是为那些谁所有搜索答案同样的问题。 答案由FragmentManager和FragmentTransaction以下语法来实现的。

This answer is for those who all searching the answer for same question. The answer is achieved by FragmentManager and FragmentTransaction with the following syntax.

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

那么你需要的片段添加到此fragmentTransaction使用以下语法。

then you need to add your fragment to this fragmentTransaction with the following syntax.

fragmentTransaction.replace(R.id.detailFragment, layout1);

最后,你必须提交事务。否则,所做的更改不会持续。

And finally you MUST commit your transaction. Otherwise changes will not persist.

fragmentTransaction.commit();

有关简短的例子来看看这个博客帖子。我希望这会帮助你。

For brief example see this blog post. I hope This will help you.

感谢你。

阅读全文

相关推荐

最新文章