如何从另一个片段打开一个新片段 [英] How do i open a new fragment from another fragment
本文介绍了如何从另一个片段打开一个新片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使片段之间的导航。我有新片段工作的NewFragment.java。我的问题是:
I tried making a navigation between fragments. I've got the NewFragment.java with the new fragment working. My problem is:
我怎么做这个onClickListener正确运行NewFragment.java?
How do i make this onClickListener run NewFragment.java correctly?
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity(), NewFragment.class);
startActivity(i);
}});
FYI:这是一个片段(我不知道是否该事项)在
FYI: This is from inside a fragment (I don't know if that matters).
推荐答案
添加以下code。在您的点击监听功能,
Add following code in your click listener function,
NextFragment nextFrag= new NextFragment();
this.getFragmentManager().beginTransaction()
.replace(R.id.Layout_container, nextFrag,TAG_FRAGMENT)
.addToBackStack(null)
.commit();
这篇关于如何从另一个片段打开一个新片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文