I am new in kotlin and retrofit, when I run this app it shows nothing in my device. But I check the logcat and found this errorNo adapter attached; skipping layout
.Sometimes ago I post this question, some people answer this but this answer not correct
CountryActivity.kt
var recyclerView: RecyclerView = findViewById(R.id.countryRecyclerView)
recyclerView.layoutManager = LinearLayoutManager(this)
var apiInterface: CountryDataInterface =
CountryApiClient.getApiClient()!!.create(CountryDataInterface::class.java)
apiInterface.getCountryData().enqueue(object : Callback<List<Country>> {
override fun onFailure(call: Call<List<Country>>, t: Throwable) {}
override fun onResponse(call: Call<List<Country>>, response: Response<List<Country>>) {
val countryData = response.body()!!
recyclerView.adapter = CountryDataAdapter(countryData)
CountryDataAdapter.kt
class CountryDataAdapter(var countryDataList: List<Country>?):
RecyclerView.Adapter<CountryDataAdapter.RecyclerViewHolder>() {
class RecyclerViewHolder(itemView: View):RecyclerView.ViewHolder(itemView) {
var countryName: TextView = itemView.findViewById(R.id.countryName)
var casesTotal: TextView = itemView.findViewById(R.id.casesTotal)
var casesToday: TextView = itemView.findViewById(R.id.casesToday)
var deathTotal: TextView = itemView.findViewById(R.id.deathTotal)
var deathToday: TextView = itemView.findViewById(R.id.deathToday)
var recoveredAll: TextView = itemView.findViewById(R.id.recoveredAll)
var activeAll: TextView = itemView.findViewById(R.id.activeAll)
var criticalAll: TextView = itemView.findViewById(R.id.criticalAll)
fun bindData(countryDataList: List<Country>?, position: Int){
countryName.text = countryDataList!!.get(position).countryName.toString()
casesTotal.text = countryDataList!!.get(position).cases.toString()
casesToday.text = countryDataList!!.get(position).todayCases.toString()
deathTotal.text = countryDataList!!.get(position).deathTotal.toString()
deathToday.text = countryDataList!!.get(position).deathToday.toString()
recoveredAll.text = countryDataList!!.get(position).recovered.toString()
activeAll.text = countryDataList!!.get(position).activePatient.toString()
criticalAll.text = countryDataList!!.get(position).critical.toString()
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
var view: View = LayoutInflater.from(parent!!.context).inflate(R.layout.country_row,parent,false)
return RecyclerViewHolder(view)
}
override fun getItemCount(): Int {
return countryDataList!!.size
}
override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) {
holder.bindData(countryDataList,position)
}
}