0

我正在尝试在单击 SherlockActionBar 上的操作项时加载新意图。我的代码如下:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.nav_plan) {
            return true;
        } else if (item.getItemId() == R.id.nav_my_plans) {
            Intent MyPlansIntent = new Intent(this, MyPlans.class);
            startActivity(MyPlansIntent);
            return true;
        } else if (item.getItemId() == R.id.nav_invites) {
            Intent InvitesIntent = new Intent(this, Invites.class);
            startActivity(InvitesIntent);
            return true;
        } else {
            return super.onOptionsItemSelected(item);
        }
    }   

    public boolean onCreateOptionsMenu(Menu paramMenu) {
        getSupportMenuInflater().inflate(R.menu.main_nav, paramMenu);
        return true;
    }

这些是我的进口:

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.app.R;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

但是,点击没有响应。难道我做错了什么?

谢谢

4

1 回答 1

1

试试这个方法:

@Override
public boolean onCreateOptionsMenu(Menu menu) { 
    getSupportMenuInflater().inflate(R.menu.main_nav, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent i;
    switch (item.getItemId()) {

    case R.id.nav_plan:
        return true;

    case R.id.nav_my_plans:
        i = new Intent(YOUR_ACTIVITY_CLASS_NAME.this, MyPlans.class);
        startActivity(i);
        return true;

    case R.id.nav_invites:
        i = new Intent(YOUR_ACTIVITY_CLASS_NAME.this, Invites.class);
        startActivity(i);
        return true;
     }
    return super.onOptionsItemSelected(item);
}
于 2012-12-05T01:26:54.067 回答