Create ListView with Fragment at dynamically in android

為{幸葍}努か 提交于 2019-12-11 10:54:08

问题


I need to create ListView with Fragment at my Sample Screen Shot View.

Screen Shots are

I know it is possible. But how do workout this types of Fragment at dynamically.

I have no idea. In this question and answers are very valuable me. Please give my solutions.

If I have mistaken for my question sorry.


回答1:


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();

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.

Thank you.




回答2:


I suggest you read this article : here And then take a look at this example : here



来源:https://stackoverflow.com/questions/11901864/create-listview-with-fragment-at-dynamically-in-android

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