如何在android的fragment内启动fragment,我正在开发一个新的应用程序,其中用户单击fragment中的图标,当用户单击icon时,我想启动一个新活动,但我不了解它在kotlin中的工作方式
在StartFragmentSession
if(it.key.endsWith("_rf")) {
attentionIcon.setColorFilter(ContextCompat.getColor(context!!, R.color.therapyInfoRedFlag))
attentionIcon.setOnClickListener {
val newFragment = TherapyInformationFragment()
val transaction = childFragmentManager.beginTransaction()
transaction.replace(R.id.therapy_fragment, newFragment)
transaction.addToBackStack(null)
transaction.commit()
}
} else if(it.key.endsWith("_yf")) {
attentionIcon.setImageResource(
R.drawable.ic_therapy_info_yellow_flag_attention
)
attentionIcon.setColorFilter(ContextCompat.getColor(context!!, R.color.therapyInfoYellowWhiteFlag))
attentionIcon.setOnClickListener {
val newFragment = TherapyInformationFragment()
val transaction = childFragmentManager.beginTransaction()
transaction.replace(R.id.therapy_fragment, newFragment)
transaction.addToBackStack(null)
transaction.commit()
}
} else {
attentionIcon.setImageResource(
R.drawable.ic_therapy_info_yellow_flag_attention
)
attentionIcon.setColorFilter(ContextCompat.getColor(context!!, R.color.therapyInfoYellowWhiteFlag))
attentionIcon.setOnClickListener {
val newFragment = TherapyInformationFragment()
val transaction = childFragmentManager.beginTransaction()
transaction.replace(R.id.therapy_fragment, newFragment)
transaction.addToBackStack(null)
transaction.commit()
}
}
我要做的是在用户单击图标时启动TherapyInformationFragment