按照说明实现 Java 代码后,当我选择导航抽屉上的课程项目时,它仍然显示与注释项目相同的内容。请帮忙 mNoteLayoutManager = new LinearLayoutManager(this); mCoursesLayoutManager = new GridLayoutManager(this, 2); List<NoteInfo> notes = DataManager.getInstance().getNotes(); mNoteRecyclerAdapter = new NoteRecyclerAdapter(this, notes); List<CourseInfo> courses = DataManager.getInstance().getCourses(); mCourseRecyclerAdapter = new CourseRecyclerAdapter(this, courses); displayNotes(); public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_notes) { displayNotes(); } else if (id == R.id.nav_courses) { displayCourses(); } else if (id == R.id.nav_share) { handleSelection("Don't you think you've shared enough"); } else if (id == R.id.nav_send) { handleSelection("Send"); } DrawerLayout drawer = findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(MainActivity.this, NoteActivity.class)); } });
1 回答
千万里不及你
TA贡献1784条经验 获得超9个赞
有几点需要注意:
我没有看到任何将活动设置为导航视图的导航项选择侦听器的代码:
navigationView.setNavigationItemSelectedListener(this);
另请务必检查 Activity_main.xml 文件中内容的顺序。Android Studio 3.5 中存在一个错误,该错误会使用 NavitationView 创建该文件并包含错误顺序的条目。包含条目需要出现在 NavigationView 条目之前(即上方)。
添加回答
举报
0/150
提交
取消