按照說明實現 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
提交
取消