I am programming using Bottom navigation, which is included in Android Studio from the beginning, but I don't know how to transition from Fragment to Activity.
After coding as below, there is no error when I run, but the moment I transition to this Fragment (the moment I move to Dashboard Fragment) the app drops on the emulator.Is there any solution?
class DashboardFragment:Fragment(){
private lateinit var dashboardViewModel
override fun onCreateView (inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?):View? {
DashboardViewModel=
ViewModelProviders.of(this).get(DashboardViewModel::class.java)
val root=inflater.inflate(R.layout.fragment_transaction, container, false)
vallayout —View=inflater.inflate(R.layout.activity_chat, null)
value: ImageView=layout.findViewById<View>(R.id.image) as ImageView
val button=layout.findViewById<Button> (R.id.start)
button.setOnClickListener{
valintent=Intent(activity, ChatActivity::class.java)
startActivity (intent)
}
return root
}
}
I can't say anything because there are no specific errors, but in the line before the error occurred,
valimage: ImageView=layout.findViewById<View>(R.id.image) as ImageView
The call has been made.If this is working, you can also find the line where the error occurred.
val button=layout.findViewById<Button> (R.id.start)
might work (add layout.
to call the View
method). If you look at reference, you can see that findViewById
is defined as both View
and Activity>.
© 2024 OneMinuteCode. All rights reserved.