【发布时间】:2014-09-26 13:24:49
【问题描述】:
在我的应用程序中,我在 ActionBar 中添加了一个 DropDown Spinner,但现在无法确定 - 如何更改每个选定下拉菜单的底部。在我的 activity_main.xml 布局(主页)中,仅包含一个显示列表的片段。我正在寻找的是,将其他 UI 屏幕也创建为 Fragment,并在每个选定的 dropDown 上更改放置的 Fragment。我的意思是主页有fragment_main.xml,选择下拉设置然后显示setting_fragment.xml 等等。我的主要是:
<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=".MainActivity"
tools:ignore="MergeRootFrame" >
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
class="terryconsulting.servicestation.AppointListFragment"
android:id="@+id/main_fragment"
/>
</FrameLayout>
在 MainActivity 类中,我实现了 ActionBar.OnNavigationListener,它调用了之前在屏幕上显示 Hello World 文本的 PlaceholderFragment。
@Override
public boolean onNavigationItemSelected(int position, long id) {
// When the given dropdown item is selected, show its contents in the
// container view.
//getFragmentManager().beginTransaction()
// .replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
// .commit();
return true;
// http://www.vogella.com/tutorials/AndroidActionBar/article.html --- ACTIONBAR ACTION
}
// As AppointListFragment is added in this activity, so need to implement this listener here
@Override
public void onFragmentInteraction(Uri uri) {
System.out.println("Into onFragmentInteraction. URL - " + uri);
return;
}
我卡在哪里:- 从下拉菜单中选择设置时,我无法确定如何调用/设置 SettingFragment。并且从设置按下Home图标返回到带有AppointListFragment的主页???
我的想法和要求,是否可行和实用?我认为应该是,因为将 Setting 称为具有自己的 ActionBar 的 Activity 并不是最好的解决方案。
请指导我,我已经搜索了很多教程,但在任何地方都找不到这种情况或带有 NavigationSelection 和 Fragments 的示例。
【问题讨论】:
标签: android android-fragments drop-down-menu navigation android-actionbar