I have bottom nav bar with 3 fragments defined in the Main activity. In one of the fragments I want to open some fragment by clicking item in recycler view under calendar view (screen 1) . When i click on it a new fragment opens with bottom nav bar (screen 2) . How to open this new fragment without bottom nav bar displaying architecturally correct?
class ScheduleFragment : Fragment(), EventCardAdapter.OnEventClickListener{
private lateinit var calendarView: CalendarView
private lateinit var recyclerView: RecyclerView
private lateinit var viewAdapter: EventCardAdapter
private lateinit var viewManager: RecyclerView.LayoutManager
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.schedule_fragment, container, false)
viewManager = LinearLayoutManager(context)
viewAdapter = EventCardAdapter(events, this)
recyclerView = view.findViewById(R.id.events_recycler_view)
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
calendarView = view.findViewById(R.id.schedule_view)
calendarView.setOnDateChangeListener { _, year, month, dayOfMonth ->
Toast.makeText(
context,
"$dayOfMonth/$month/$year",
Toast.LENGTH_LONG
).show()
}
recyclerView.apply {
setHasFixedSize(true)
layoutManager = viewManager
adapter = viewAdapter
}
}
// moving to fragment by clicking item in recycler
override fun onEventClick(view: View, position: Int) {
view.findNavController().navigate(R.id.action_scheduleFragment_to_attendanceEntryFragment)
}
}
on the hosted activity implement on destination changed listener callback then when destination id equal to one of the fragments u want to show nav bar on it set nav bar visibilty to visible else set it to gone
navController.addOnDestinationChangedListener{}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.