gpt4 book ai didi

android - 在导航栏中切换 fragment

转载 作者:行者123 更新时间:2023-11-29 01:52:43 25 4
gpt4 key购买 nike

我的主要 Activity 是这样的:

public class EntryPoint extends SherlockFragmentActivity implements ActionBar.OnNavigationListener

还有两个 fragment ,当你在导航栏中选择一个项目时我只想切换,所以我有这个方法在 Nexus 7(目标版本 4.2.2)中工作但在 Xperia Neo V(目标版本4.0.3 版)。第一个 fragment 出现没有问题,但是当我换到另一个 fragment 时,我调试了它,它没有执行 onCreate 或 onCreateView 方法。这就是为什么它在尝试访问 fragment 中的列表时会出现异常。奇怪的是,在 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;
}

两个 fragment 是这样的:

public class CityListFragment extends SherlockListFragment implements
com.actionbarsherlock.widget.SearchView.OnQueryTextListener {

和容器:

<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>

最佳答案

Ismael Reyes 交谈,他找到了答案:

Android 中是否存在此问题:https://code.google.com/p/android/issues/detail?id=18594

然后回答:

"[...] editing src/com/example/android/supportv4/app/LoaderCustomSupport.java to remove the references to OnQueryTextListener and the onCreateOptionsMenu, onQueryTextChange, and onQueryTextSubmit functions [...]" Dianne Hackborn

关于android - 在导航栏中切换 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16987764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com