我正在尝试使用 MenuItem 调用其他 activity
I´m trying to call other activity with MenuItem
我正在尝试使用 onCreateOptionsMenu 和 onOptionsItemSelected 调用其他 activity,但我不知道调试是不可能的,而且它不执行操作,我有
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.login_settings, menu);º
//return super.onCreateOptionsMenu(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getGroupId();
if(id == R.id.contactMenu) {
Intent intent = new Intent(this, ContactActivity.class);
this.startActivity(intent);
return super.onOptionsItemSelected(item);
}
return true;
}
和菜单项
<group
android:id="@+id/contactMenu"
android:checkableBehavior="single">
<item
android:id="@+id/contactSettings"
android:icon="@drawable/correo"
android:title="@string/ContactUs_settings" />
</group>
非常感谢...
像下面的代码一样更改并工作 fine.You 必须为 select menuItem
使用 ItemId
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId(); //you must use item id not group id
if(id == R.id.contactSettings) {
Intent intent = new Intent(this, ContactActivity.class);
startActivity(intent);
}
return true;
}
我正在尝试使用 onCreateOptionsMenu 和 onOptionsItemSelected 调用其他 activity,但我不知道调试是不可能的,而且它不执行操作,我有
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.login_settings, menu);º
//return super.onCreateOptionsMenu(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getGroupId();
if(id == R.id.contactMenu) {
Intent intent = new Intent(this, ContactActivity.class);
this.startActivity(intent);
return super.onOptionsItemSelected(item);
}
return true;
}
和菜单项
<group
android:id="@+id/contactMenu"
android:checkableBehavior="single">
<item
android:id="@+id/contactSettings"
android:icon="@drawable/correo"
android:title="@string/ContactUs_settings" />
</group>
非常感谢...
像下面的代码一样更改并工作 fine.You 必须为 select menuItem
使用 ItemId@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId(); //you must use item id not group id
if(id == R.id.contactSettings) {
Intent intent = new Intent(this, ContactActivity.class);
startActivity(intent);
}
return true;
}