【发布时间】:2015-08-24 13:48:05
【问题描述】:
我有一个类似于演示文稿的 Activity,我想放置一些按钮,以便我可以直接转到特定片段(我从 MainActivity 中选择的片段)。
我已尝试使用 getSupportFragment 和 Activity.getSupportFragment 但没有任何效果。而且,显然,两者都不是出于简单的意图。
谢谢。
这是 MainActivity “Splash”:
public class Splash extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay_splash);
}
}
FragmentActivity 的开始。它不完整,因此包含错误。这是包含 Fragments 的 Activity
public class FragmentActivity extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
/**
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
*/
private CharSequence mTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
要在视图之间切换,我使用:
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment views=null;
switch (position) {
case 0:
//news
views= new news();
break;
case 1:
//time
views=new time();
break;
case 2:
//Ins
views=new Ins() ;
break;
}
fragmentManager.beginTransaction()
.replace(R.id.container, views)
.commit();
}
【问题讨论】:
-
请附上一些现有的代码
-
我不明白:你需要什么?片段在哪里?请放一个屏幕或一些代码:)
-
已编辑。抱歉耽搁了
-
Np,我还有一个问题:如果我明白了,您有一个包含 3 个(或更多)片段的页面,并且根据单击的按钮,您想让特定片段可见,其他片段隐藏对吗?
-
是的,我有一个我想像“预菜单”一样的活动。在它(Splash Activity)中,我想放置一些引用每个片段的按钮。所以,如果我按下名为“时间”的按钮,我会显示显示时间视图的片段活动。
标签: android android-activity fragment navigation-drawer