навигационный пункт назначения xxx неизвестен этому NavController - PullRequest
0 голосов
/ 28 сентября 2019

У меня есть bottomSheetDialogFragment, который открывается из HomeFragment (часть navigationcontroller).Я хочу открыть другое назначение при нажатии кнопки внутри bottomSheetDialogFragment, но при этом оно дает мне «назначение, неизвестное этому NavigationController»

HomeFragment.kt

override fun onClick(view: View?) {
        when (view) {
            binding.ivBacktrack -> {
                val upgradePremBottomSheet =
                    UpgradePremiumMembershipBottomSheetDialogFragment.newInstance()
                upgradePremBottomSheet.show(childFragmentManager, null)
            }
            binding.ivInterested -> displayToast()
            binding.ivNotInterested -> displayToast()
            binding.ivMessage -> {
                val directMessageBottomSheet = DirectMessageBottomDialogFragment.newInstance()
                directMessageBottomSheet.show(childFragmentManager, "Direct Message Bottom Sheet")
            }
        }
    }

DirectMessageBottomDialogFragment.kt

class DirectMessageBottomDialogFragment : BottomSheetDialogFragment(), View.OnClickListener {

    lateinit var binding: LayoutDirectMessageLimitReachedBottomSheetBinding

    companion object{
        fun newInstance(): DirectMessageBottomDialogFragment{
            return DirectMessageBottomDialogFragment()
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = LayoutDirectMessageLimitReachedBottomSheetBinding.inflate(inflater,container,false)
        binding.clDmLimitReachedBottomSheet.setBackgroundColor(ContextCompat.getColor(
            context!!, R.color.background_black
        ))
        return binding.root
    }

    override fun onStart() {
        super.onStart()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.tvGetPremiumMembership.setOnClickListener(this)
        binding.tvPurchaseDmPacks.setOnClickListener(this)
        binding.ivClose.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v){
            binding.tvGetPremiumMembership -> findNavController().navigate(R.id.action_directMessageBottomDialogFragment_to_paymentFragment)
            binding.tvPurchaseDmPacks -> findNavController().navigate(R.id.action_directMessageBottomDialogFragment_to_dmPackFragment)
            binding.ivClose -> dismiss()
        }
    }
}

Любая помощь приветствуется

1 Ответ

0 голосов
/ 30 сентября 2019

Можете ли вы предоставить свой XML-файл с графиком навигации?Проблема заключается в том, что вы пытаетесь перемещаться с помощью действия, которое не определено в XML-файле графика навигации, связанном с вашим BottomSheetDialog.Попробуйте заменить findNavController().navigate() на requireView().findNavController().navigate() и посмотрите, работает ли он.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...