[英]Switching fragments in navigation bar
I have my main Activity in this way: 我的主要活动是这样的:
public class EntryPoint extends SherlockFragmentActivity implements ActionBar.OnNavigationListener
And two fragments that I only want to switch when you select one item in the navigation bar, so I have this method that is working in the Nexus 7 (target version 4.2.2) but not in the Xperia Neo V (target version 4.0.3). 还有两个片段,当您在导航栏中选择一个项目时,我只想切换它们,所以我有这种方法适用于Nexus 7(目标版本4.2.2),但不适用于Xperia Neo V(目标版本4.0)。 3)。 The first fragment appear without problem, but when I change to the other fragment, I debugged it and it doesn't execute the method onCreate or onCreateView.
第一个片段似乎没有问题,但是当我切换到另一个片段时,我对其进行了调试,并且它不执行onCreate或onCreateView方法。 And thats why it through an exception when trying to access to the list in the fragments.
这就是为什么在尝试访问片段中的列表时会通过异常的原因。 The wierd thing is that in the Nexus 7 works perfect but in the SonyEriccson no.
奇怪的是,Nexus 7可以完美运行,而SonyEriccson则可以。
@Override
public boolean onNavigationItemSelected(int position, long id) {
// When the given dropdown item is selected, show its contents in the
// container view.
int section = position + 1;
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
if (section == 1) {
ft.add(R.id.container,new FavCityListFragment());
} else if (section == 2) {
ft.remove(getFav());
ft.add(R.id.container,new CityListFragment());
ft.addToBackStack(null);
}
ft.commit();
return true;
}
The two fragments are like this one: 这两个片段是这样的:
public class CityListFragment extends SherlockListFragment implements
com.actionbarsherlock.widget.SearchView.OnQueryTextListener {
And the container: 和容器:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EntryPoint"
tools:ignore="MergeRootFrame" >
</FrameLayout>
Talking to Ismael Reyes , he found the answer: 与Ismael Reyes交谈时,他找到了答案:
Is this issue in Android: https://code.google.com/p/android/issues/detail?id=18594 Android中是否存在此问题: https : //code.google.com/p/android/issues/detail?id=18594
And to answer it: 并回答:
"[...] editing src/com/example/android/supportv4/app/LoaderCustomSupport.java to remove the references to OnQueryTextListener and the onCreateOptionsMenu, onQueryTextChange, and onQueryTextSubmit functions [...]" Dianne Hackborn
“ [...编辑src / com / example / android / supportv4 / app / LoaderCustomSupport.java以删除对OnQueryTextListener和onCreateOptionsMenu,onQueryTextChange和onQueryTextSubmit函数的引用[...]” Dianne Hackborn
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.