如何开始片段内的片段?

时间:2018-12-28 14:16:05

标签: android-intent kotlin fragment

如何在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

0 个答案:

没有答案