key 123 items ['word1', 'word2', 'word3']
key 456 items ['word4']
下面是activity_home的代码
public class home_fragment extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private AppBarConfiguration mAppBarConfiguration;
private DrawerLayout drawer;
private ImageView profilepic;
private DatabaseReference mDatabaseRef;
private FirebaseAuth mAuth;
private StorageReference storageReference;
FirebaseUser firebaseUser;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navi_home:
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment,new com.example.docsapp.HomeFragment()).commit();
break;
case R.id.navi_favourites:
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment,new FavouriteFragment()).commit();
break;
case R.id.navi_search:
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment,new SearchFragment()).commit();
break;
}
return true;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mAuth=FirebaseAuth.getInstance();
firebaseUser = mAuth.getCurrentUser();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
try {
BottomNavigationView navigation = findViewById(R.id.nav_view);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}catch (Exception e){
FancyToast.makeText(getApplicationContext(),e.getMessage(),FancyToast.LENGTH_LONG,FancyToast.ERROR,true).show();
}
if (savedInstanceState==null){
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new HomeFragment()).commit();
try {
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment,new com.example.docsapp.HomeFragment()).commit();
}catch (Exception e){
FancyToast.makeText(getApplicationContext(),e.getMessage(),FancyToast.LENGTH_LONG,FancyToast.ERROR,true).show();
}
}
UpdateNavHeader();
}
下面是home_fragment的代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:background="@color/colorPrimary"
android:id="@+id/toolbar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"/>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_home"
app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
我正在尝试从一个片段中打开一个片段。试图打开的片段显示错误.home片段由导航抽屉和底部导航组成。
我正在尝试从一个片段中打开一个片段。我试图打开的片段显示错误.home片段包含一个导航抽屉以及底部导航。
在显示运行时间here时显示错误。