本文整理匯總了Java中android.view.MenuItem.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuItem.equals方法的具體用法?Java MenuItem.equals怎麽用?Java MenuItem.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.MenuItem
的用法示例。
在下文中一共展示了MenuItem.equals方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: selectMenu
import android.view.MenuItem; //導入方法依賴的package包/類
private void selectMenu(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_home:
currentFragment = HomeFragment.newInstance();
break;
case R.id.action_course:
currentFragment = CourseFragment.newInstance();
break;
case R.id.action_schedule:
currentFragment = ScheduleFragment.newInstance();
break;
case R.id.action_about:
currentFragment = AboutFragment.newInstance();
break;
}
if (currentItem == null || !item.equals(currentItem)) {
item.setChecked(true);
FragmentTransaction beginTransaction = getSupportFragmentManager().beginTransaction();
beginTransaction.replace(R.id.container, currentFragment);
beginTransaction.commit();
}
currentItem = item;
}
示例2: onNavigationItemSelected
import android.view.MenuItem; //導入方法依賴的package包/類
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
if (isRunning && !item.equals(runItem)) {
dialogQuitRun(item);
return false;
}
if (!(isRunning && item.equals(runItem))) {
if (itemStack.isEmpty() || !itemStack.peek().equals(item)) {
itemStack.push(item);
}
showSearchBar();
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_profile) {
toolbar.setTitle("Profile");
launchFragment(new ProfileFragment());
} else if (id == R.id.nav_run) {
toolbar.setTitle("Run");
hideSearchBar();
launchFragment(new RunningMapFragment());
} else if (id == R.id.nav_new_challenge) {
toolbar.setTitle("Search someone");
launchFragment(new EmptySearchFragment());
searchView.setQueryHint("Search someone");
searchViewAsMenuItem.expandActionView();
} else if (id == R.id.nav_messages) {
toolbar.setTitle("Challenges");
launchFragment(new MessagesFragment());
} else if (id == R.id.nav_history) {
toolbar.setTitle("History");
launchFragment(new HistoryFragment());
} else if (id == R.id.nav_logout) {
itemStack.pop();
dialogLogout();
}
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}