getting this error for enqueue for kotlin android and it is showing Unresolved reference: enqueue
my code
class NewsActivity : AppCompatActivity() {
private lateinit var mRecyclerView: RecyclerView
private lateinit var mProgressBar: ProgressBar
private lateinit var mAdapter: NewsAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_news)
mRecyclerView = findViewById(R.id.recycler_view)
mProgressBar = findViewById(R.id.progress_circular)
getItemList()
}
private fun getItemList() {
mProgressBar.visibility = View.VISIBLE
val apical = ApiClient.create().getData()
apical.enqueue(object : retrofit2.Callback<List<DataModelItem>> {
override fun onFailure(call: Call<List<DataModelItem>>, t: Throwable) {
mProgressBar.visibility = View.GONE
}
override fun onResponse(
call: Call<List<DataModelItem>>,
response: Response<List<DataModelItem>>) {
if (response.isSuccessful){
val itemListNews = response.body()!!
mAdapter = NewsAdapter(itemListNews)
val layoutManager = LinearLayoutManager(this@NewsActivity)
mRecyclerView.layoutManager = layoutManager
mRecyclerView.adapter = mAdapter
}
}
})
}
}
this is News activity
class NewsAdapter(private val itemList : List<DataModelItem>) : RecyclerView.Adapter<NewsAdapter.CustomViewHolder>() {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): NewsAdapter.CustomViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_view, parent, false)
return CustomViewHolder(view)
}
override fun getItemCount(): Int {
return itemList.size
}
override fun onBindViewHolder(holder: NewsAdapter.CustomViewHolder, position: Int) {
val itemData = itemList.get(position)
Picasso.get().load(itemData.images).into(holder.img1)
holder.Titlenews.setText(itemData.title)
holder.txt_description.setText(itemData.summary)
holder.publish_time.setText(itemData.publish_date)
}
inner class CustomViewHolder(view: View): RecyclerView.ViewHolder(view){
var img1:ImageView
var Titlenews: TextView
var txt_description: TextView
var publish_time: TextView
init {
img1 = view.findViewById(R.id.item_image)
Titlenews = view.findViewById(R.id.Titlenews)
txt_description = view.findViewById(R.id.txt_description)
publish_time = view.findViewById(R.id.publish_time)
}
}
}
this is the news adapter
object ApiClient {
var BASE_URL = ""
fun create() :Api{
val retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build()
return retrofit.create(Api::class.java)
}
}
this is Api client
Help required
I want not getting a solution as always it is giving me an error for enqueue .
Try changing
to