当前位置: 首页>>代码示例>>Java>>正文


Java OnNavigationItemSelectedListener类代码示例

本文整理汇总了Java中android.support.design.widget.NavigationView.OnNavigationItemSelectedListener的典型用法代码示例。如果您正苦于以下问题:Java OnNavigationItemSelectedListener类的具体用法?Java OnNavigationItemSelectedListener怎么用?Java OnNavigationItemSelectedListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OnNavigationItemSelectedListener类属于android.support.design.widget.NavigationView包,在下文中一共展示了OnNavigationItemSelectedListener类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupDrawerContent

import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            switch (menuItem.getItemId()) {
                case R.id.navItem1:
                    Intent alarm = new Intent(AlarmClock.ACTION_SET_ALARM);
                    startActivity(alarm);
                    break;
                case R.id.navItem2:
                    try {
                        export();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    break;
            }
            return false;
        }
    });
}
 
开发者ID:cao1rui2,项目名称:MDSimpleNotes,代码行数:25,代码来源:MainActivity.java

示例2: onCreateView

import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_menu, container,
              false);
      
      
      
      //得到左侧的列表
      NavigationView navigationView = (NavigationView) view.findViewById(R.id.vNavigation);
      //设置监听
      navigationView.setNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {
	
	@Override
	public boolean onNavigationItemSelected(MenuItem menuItem) {
		String title = (String) menuItem.getTitle();
		//Toast.makeText(getActivity(), "您点击了 " + title, Toast.LENGTH_SHORT).show();
		switch (title) {
		case "首页":
			Toast.makeText(getActivity(), "这已经是首页了,你再点试试看?", Toast.LENGTH_SHORT).show();
			break;
		case "随手记":
			Intent intent1 = new Intent(getActivity(), MemoActivity.class);
			startActivity(intent1);
			MainActivity.handler.sendEmptyMessage(1);//通知关闭左侧栏
			break;
		case "便签":
			Intent intent2 = new Intent(getActivity(), AtyList.class);
			startActivity(intent2);
			MainActivity.handler.sendEmptyMessage(1);//通知关闭左侧栏
			break;
			
		case "天气":
			Intent intent4 = new Intent(getActivity(), WeatherActivity.class);
			startActivity(intent4);
			MainActivity.handler.sendEmptyMessage(1);//通知关闭左侧栏
			break;
		case "关于":
			Toast.makeText(getActivity(), "这里没什么东西~", Toast.LENGTH_LONG).show();
			MainActivity.handler.sendEmptyMessage(1);//通知关闭左侧栏
			break;
		default:
			break;
		}
		return false;
	}
});
     
      return  setupReveal(view) ;
  }
 
开发者ID:cckevincyh,项目名称:C.,代码行数:50,代码来源:MyMenuFragment.java

示例3: getParent

import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
@Nullable private OnNavigationItemSelectedListener getParent() {
    Activity activity = getActivity();
    if (activity instanceof OnNavigationItemSelectedListener) {
        return (OnNavigationItemSelectedListener) activity;
    }
    return null;
}
 
开发者ID:drakeet,项目名称:TimeMachine,代码行数:8,代码来源:DrawerDelegate.java

示例4: setupNavigationView

import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
private void setupNavigationView(NavigationView view) {
    view.setNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (mCurrentNavItem == menuItem.getItemId()) {
                mDrawerLayout.closeDrawers();
                return true;
            }

            switch (menuItem.getItemId()) {
                case R.id.drawer_menu_library:
                    setFragment(new LibraryFragment());
                    break;
                case R.id.drawer_menu_browser:
                    setFragment(new BrowserFragment());
                    break;
                case R.id.drawer_menu_about:
                    setTitle(R.string.menu_about);
                    setFragment(new AboutFragment());
                    break;
            }

            mCurrentNavItem = menuItem.getItemId();
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}
 
开发者ID:nkanaev,项目名称:bubble,代码行数:30,代码来源:MainActivity.java

示例5: setNavigationItemSelectedListener

import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
public void setNavigationItemSelectedListener(@Nullable OnNavigationItemSelectedListener listener) {
    navigationView.setNavigationItemSelectedListener(listener);
}
 
开发者ID:st1hy,项目名称:Red-Calorie,代码行数:4,代码来源:DrawerView.java

示例6: attach

import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
/**
 * Attach the fragment to hold the drawer and toolbar
 *
 * @param parent a Activity that extends AppCompatActivity & OnNavigationItemSelectedListener
 * @return {@link DrawerDelegate}
 */
public static <ParentActivity extends AppCompatActivity & OnNavigationItemSelectedListener> DrawerDelegate attach(
    @Nullable ParentActivity parent) {
    return attach(parent.getSupportFragmentManager());
}
 
开发者ID:drakeet,项目名称:TimeMachine,代码行数:11,代码来源:DrawerDelegate.java


注:本文中的android.support.design.widget.NavigationView.OnNavigationItemSelectedListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。