Android的碎片没有查看发现的ID? [英] Android Fragment no view found for ID?
问题描述
我有一个片段,我想加入到一个视图。
I have a fragment I am trying to add into a view.
FragmentManager fragMgr=getSupportFragmentManager();
feed_parser_activity content = (feed_parser_activity)fragMgr
.findFragmentById(R.id.feedContentContainer);
FragmentTransaction xaction=fragMgr.beginTransaction();
if (content == null || content.isRemoving()) {
content=new feed_parser_activity(item.getLink().toString());
xaction
.add(R.id.feedContentContainer, content)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(null)
.commit();
Log.e("Abstract", "DONE");
}
在执行此code,我得到以下错误调试。
When this code is executed I get the following error in debug..
java.lang.IllegalArgumentException: No view found for id 0x7f080011
for fragment feed_parser_activity{41882f50 #2 id=0x7f080011}
feed_parser_activity
是设置为XML片段布局中的片段。
我使用的是FragmentActivity主办的片段布局保持了 feed_parser_layout
。
我是不是该编码上述正确?
feed_parser_activity
is a Fragment that is set to Fragment layout in xml.
I am using a FragmentActivity to host the Fragment Layout holding the feed_parser_layout
.
Am I coding this correctly above?
推荐答案
我是有这个问题太多,直到我意识到,我已经指定了的setContentView错误的布局()
的onCreate()法>
I was having this problem too, until I realized that I had specified the wrong layout in setContentView()
of the onCreate()
method of the FragmentActivity.
传入 FragmentTransaction.add的ID()
,你的情况 R.id.feedContentContainer
,必须)在的setContentView(指定的布局
。
The id passed into FragmentTransaction.add()
, in your case R.id.feedContentContainer
, must be a child of the layout specified in setContentView()
.
您没有向我们展示你的的onCreate()
的方法,所以这也许是同样的问题。
You didn't show us your onCreate()
method, so perhaps this is the same problem.
这篇关于Android的碎片没有查看发现的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!