I'm learning Kotlin
in Adroid Studio and recently I have stuck on RecyclerView
.
The problem is that I'm not able to go forward due to error showing on LinearLayoutManager(this)
.
My little code looks like:
package com.store.example
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.fragment_store.*
class StoreFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// call recyclerView this id (fragment_store)
recyclerView.layoutManager = LinearLayoutManager(this)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_store, container, false)
}
}
My XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StoreFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/card_view_store" />
</FrameLayout>
LinearLayoutManager(this)
is underlined and tells me that:
Type mismatch: inferred type is StoreFragment but Context! was expected
I'm not a advanced programist, rather a newbie and I've been trying to fix this remark but at this moment its beyond my skills.
Thank you for your help.