简体   繁体   English

通过导航抽屉在活动之间切换

[英]Switching between activities through Navigation Drawer

I have 2 activities which extend a base activity: 我有2个活动扩展了基本活动:

Class BaseActivity extends Activity
Class A extends BaseActivity
Class B extends BaseActivity

Now I have a button on A which allows the user to go to B , and a button on B which allows to go back to A . 现在,我在A上有一个按钮,该按钮允许用户转到B上 ,在B上有一个按钮,可以返回到A。

So far, so good. 到现在为止还挺好。
Now after reading this documentation, which is straightforward enough, I am implementing an additional activity between BaseActivity and A , B . 现在,在阅读了这份非常简单的文档之后,我将在BaseActivityAB之间实现一个额外的活动。 The structure will be: 结构将是:

Class BaseActivity extends Activity
Class MyDrawer extends BaseActivity
Class A extends MyDrawer
Class B extends MyDrawer

The activity MyDrawer contains the code to use a Navigation Drawer. 活动MyDrawer包含使用导航抽屉的代码。 The problem I have is, I am not able to understand how do I use my Activities instead of Fragments in the Navigation Drawer. 我遇到的问题是,我无法理解如何使用“活动”而不是导航抽屉中的“片段”。 I want the users to be able to switch between activities through the drawer. 我希望用户能够通过抽屉在活动之间进行切换。 Is this possible? 这可能吗? or do I need to rewrite everything using Fragments instead of Activities? 还是我需要使用片段而不是活动来重写所有内容?

Any help is appreciated. 任何帮助表示赞赏。

Use intent's to switch between the activities. 使用意图在活动之间切换。 Refer to Navigation Drawer to switch between activities 请参考导航抽屉在活动之间进行切换

public void selectItem(int position) {
Intent intent = null;
switch(position) {
    case 0:
        intent = new Intent(this, Activity_0.class);
        break;
    case 1:
        intent = new Intent(this, Activity_1.class);
        break;

    ...


    case 4: 
        intent = new Intent(this, Activity_4.class);
        break;

    default : 
        intent = new Intent(this, Activity_0.class); // Activity_0 as default
        break;
}

startActivity(intent);

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM