将操作栏按钮与Android中的Activity链接?

时间:2014-12-03 16:46:18

标签: android android-activity android-actionbar settings

如何将操作栏中的设置按钮与另一个活动相关联。

@Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch(item.getItemId()){
        case R.id.about:
            about(); // shows a dialogbox
            break;
        case R.id.settings:
            // I want to link this with my setting screen
            break;
        }
        return super.onOptionsItemSelected(item);
    }

我将关于操作栏按钮与对话框联系起来,但对于我的设置,我希望它转到另一个活动。我怎样才能做到这一点?我想要链接的活动叫做settings.java

1 个答案:

答案 0 :(得分:0)

这个怎么样?

@Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch(item.getItemId()){
        case R.id.about:
            about(); // shows a dialogbox
            break;
        case R.id.settings:
            startActivity(this, settings.class);
            // This doesn't work?
            break;
        }
        return super.onOptionsItemSelected(item);
    }