4

Guys i know this has asked for sometimes, but i still confused over this problem. (I'm quite new in android development)

So i have this OrderDetailFragment.kt

class OrderDetailFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        // Declaration of Overflow menu
        setHasOptionsMenu(true)

        // Change action bar title
        (activity as AppCompatActivity).supportActionBar?.title = "Order Details"

        // Layout binding between Fragment Layout and Activity
        val binding: FragmentOrderDetailBinding = DataBindingUtil.inflate(inflater,     R.layout.fragment_order_detail, container, false)

        // Switch Button Onclick Handler
        binding.switchProductButton.setOnClickListener{

            // Initialize a new layout inflater instance (The Error is here)
            val inflater:LayoutInflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater

            // Inflate a custom view using layout inflater
            val view = inflater.inflate(R.layout.switch_product_layout,null)

            // Initialize a new instance of popup window
            val popupWindow = PopupWindow(
                view, // Custom view to show in popup window
                ConstraintLayout.LayoutParams.WRAP_CONTENT, // Width of popup window
                ConstraintLayout.LayoutParams.WRAP_CONTENT // Window height
            )

        }
    }

    return binding.root

}

}

The error is at line

val inflater:LayoutInflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater

The error says :

Type Mismatch. Required Context Found String

Am i missing something ?

dimas hermanto
  • 369
  • 7
  • 22

0 Answers0