我正在尝试为应用程序创建双窗格/单个窗格设置。在我把所有的内脏放入碎片之前,它工作得很好,我不知道是什么导致它不能工作。当我进行方向变更时,问题就在发生。起初,它不是由于某种原因重新创建视图。它会调用onCreateView,但我无法获得视图内的列表视图的处理,并得到空(我知道我有布局正确的风景和肖像,因为它在纵向和横向工作,如果它开始在那里)。所以,我所做的是将setRetainInstance添加为true,认为这可以解决我的问题。那么,现在我得到了没有发现身份证的其他问题。Android碎片未找到id为id
我认为现在发生的事情是,它试图将自己重新附加到方向改变之前的ID中,并且它不像现在在不同的布局上那样存在。我试着创建一个新的片段并添加它,但这也不起作用。我边缘拉着我的头发试图与Android的工作有思想片段系统,几乎不可能合作。任何帮助,将不胜感激。下面是相关代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.study_guide);
//Create The Ad Service
//Check to see if the view is landscape or portrait
if (this.findViewById(R.id.singlePaneStudyGuide) != null) {
mDualPane = false;
} else if (this.findViewById(R.id.doublePaneStudyGuide) != null) {
mDualPane = true;
}
LinearLayout layout = (LinearLayout)findViewById(R.id.addbox);
adView = new AdView(this,AdSize.SMART_BANNER,"a1511f0352b42bb");
layout.addView(adView);
AdRequest r = new AdRequest();
r.setTesting(true);
adView.loadAd(r);
//Inflate Fragments depending on which is selected
//if (savedInstanceState == null) {
FragmentManager fm = this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
SGListFragment newFrag = new SGListFragment();
if (mDualPane == true) {
ft.add(R.id.sgScrollContainer, newFrag, "SgListView").commit();
} else {
ft.add(R.id.singlePaneStudyGuide, newFrag, "SgListView").commit();
}
fm.executePendingTransactions();
//}
}
我用尽寻找与该片段经理片段和重新分配给不同的布局,但由于某种原因,它仍然在寻找旧的。
请发表您的代码 – Kerry 2013-02-17 08:22:44
也请添加study_guide.xml的内容为纵向和横向 – 2013-02-18 17:41:30