Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MainFragment : android.app.Fragment() {
- // TODO: Rename and change types of parameters
- private var param1: String? = null
- private var param2: String? = null
- lateinit var navigationView: BottomNavigationView
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- arguments?.let {
- // param1 = it.getString(ARG_PARAM1)
- // param2 = it.getString(ARG_PARAM2)
- }
- }
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
- savedInstanceState: Bundle?): View? {
- // Inflate the layout for this fragment
- var view : View = inflater.inflate(R.layout.fragment_main, container, false)
- navigationView = view.findViewById(R.id.navigation)
- navigationView.setOnNavigationItemReselectedListener{mOnNavigationItemSelectedListener}
- return view
- }
- private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
- when (item.itemId) {
- R.id.navigation_daylifeed -> {
- //message.setText(R.string.title_home)
- openFragment("DailyFeedFragment")
- return@OnNavigationItemSelectedListener true
- }
- R.id.navigation_notices -> {
- //message.setText(R.string.title_dashboard)
- openFragment("NoticesFragment")
- return@OnNavigationItemSelectedListener true
- }
- R.id.navigation_attendence -> {
- //message.setText(R.string.title_notifications)
- openFragment("AttendenceFragment")
- return@OnNavigationItemSelectedListener true
- }
- }
- false
- }
- fun openFragment(fragment: String) {
- val manager = fragmentManager
- val transaction = manager.beginTransaction()
- // animation
- // transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out)
- if(fragment.equals("DailyFeedFragment")) {
- transaction.replace(R.id.frame_container, DailyFeedFragment.newInstance("", "")) // newInstance() is a static factory method.
- transaction.addToBackStack(null)
- transaction.commit()
- }
- else if(fragment.equals("NoticesFragment")){
- transaction.replace(R.id.frame_container, NoticesFragment.newInstance("", "")) // newInstance() is a static factory method.
- transaction.addToBackStack(null)
- transaction.commit()
- }
- else{
- transaction.replace(R.id.frame_container, AttendenceFragment.newInstance("", "")) // newInstance() is a static factory method.
- transaction.addToBackStack(null)
- transaction.commit()
- }
- }
- companion object {
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- *
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment MainFragment.
- */
- // TODO: Rename and change types and number of parameters
- @JvmStatic
- fun newInstance(param1: String, param2: String) =
- MainFragment().apply {
- arguments = Bundle().apply {
- // putString(ARG_PARAM1, param1)
- // putString(ARG_PARAM2, param2)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement