public class Employee_mainScreen extends AppCompatActivity {
private ViewPager viewPager;
Button logout;
FirebaseAuth mFirebaseauth;
private FirebaseAuth.AuthStateListener mAuthStateListener;
e_HomeFragment homeF;
e_ProfileFragment profileF;
e_MessagesFragment messageF;
e_SavedFragment savedF;
private BottomNavigationView.OnNavigationItemSelectedListener e_navListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()) {
case R.id.nav_home:
selectedFragment = new e_HomeFragment();
break;
case R.id.nav_saved:
selectedFragment = new e_SavedFragment();
break;
case R.id.nav_messages:
selectedFragment = new e_MessagesFragment();
break;
case R.id.nav_profile:
selectedFragment = new e_ProfileFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.e_fragment_container,
selectedFragment).commit();
return true;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.e_employee_mainscreen);
BottomNavigationView bottomNav = findViewById(R.id.e_bottom_navigation);
bottomNav.setOnNavigationItemSelectedListener(e_navListener);
getSupportFragmentManager().beginTransaction().replace(R.id.e_fragment_container,
new e_HomeFragment()).commit();}}
Это мои коды для экрана, где моя нижняя навигация равна
public class e_SectionsPageAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public void addFragment(Fragment fragment, String title){
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
public e_SectionsPageAdapter(FragmentManager fm) {
super(fm);
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
}
Это адаптер моей нижней навигации
public class e_HomeFragment extends Fragment {
private RecyclerView mrecyclerView;
private JobsAdapter adapter;
FirebaseAuth mfirebaseauth;
private DatabaseReference mdatabase;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.e_fragment_home,container,false);
mfirebaseauth = FirebaseAuth.getInstance();
mrecyclerView = view.findViewById(R.id.recycler_View);
mrecyclerView.setHasFixedSize(true);
mrecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
String user_id = mfirebaseauth.getCurrentUser().getUid();
FirebaseRecyclerOptions<Jobs> options =
new FirebaseRecyclerOptions.Builder<Jobs>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("Jobs"), Jobs.class)
.build();
adapter = new JobsAdapter(options);
mrecyclerView.setAdapter(adapter);
return view;
}
@Override
public void onStart() {
super.onStart();
adapter.startListening();
}
@Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
}
Это мой домашний фрагмент, гдепредставление переработчика пожарной базы
public class JobsAdapter extends FirebaseRecyclerAdapter<Jobs, JobsAdapter.JobsViewHolder> {
private DatabaseReference UserRef;
public JobsAdapter(@NonNull FirebaseRecyclerOptions<Jobs> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull final JobsViewHolder holder, int i, @NonNull Jobs jobs) {
String userID = getRef(i).getKey();
UserRef.child(userID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String c = dataSnapshot.child("company").getValue().toString();
String d = dataSnapshot.child("description").getValue().toString();
String p = dataSnapshot.child("position").getValue().toString();
holder.Pos.setText(p);
holder.Des.setText(d);
holder.Com.setText(c);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@NonNull
@Override
public JobsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.e_layout_listitem, parent, false);
UserRef = FirebaseDatabase.getInstance().getReference().child("Jobs");
return new JobsViewHolder(view);
}
public class JobsViewHolder extends RecyclerView.ViewHolder{
TextView Pos, Des, Com;
public JobsViewHolder(@NonNull View itemView) {
super(itemView);
Pos = itemView.findViewById(R.id.titleTv);
Des = itemView.findViewById(R.id.companyTv);
Com = itemView.findViewById(R.id.descriptionTv);
}
}
}
А это адаптер переработчика пожарной базы
Спасибо за все ответы, которые я получу
Мне действительно нужно это исправить в ближайшее время