我在代码的这一行显示此错误:

 quantityFragment.show(fragManager, "Quantity")



产品适配器
        itemView.bAddToCart.setOnClickListener {
            UserInfo.tempProdId = tempProdId

            // Show the fragment

            var quantityFragment = QuantityFragment()
            var fragManager = (itemView.context as Activity).fragmentManager

            quantityFragment.show(fragManager, "Quantity")

        }

数量片段
class QuantityFragment : DialogFragment() {

override fun onCreateView(
  inflater: LayoutInflater,
  container: ViewGroup?,
  savedInstanceState: Bundle?): View? {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_quantity, container, false)
  }
}

请帮帮我^ _ ^

最佳答案

您正在使用android.support.v4.app.DialogFragment,因此我们需要传递supportFragmentManager而不是将fragmentManager传递给show方法

09-11 03:31