我正在尝试在SherlockActionBar上点击actionitem加载新意图。我的代码如下:
@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;
但是,点击无响应。我做错了吗?
由于
答案 0 :(得分: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);
}