Конвертируемые данные Gson не устанавливаются в Recyclerview с использованием Retrofit2 и rxjava2, а затем его Ошибка выдачи:
"kotlin.UninitializedPropertyAccessException: свойство lateinit ComboDisposable не было инициализировано"
MainActivity.kt
internal lateinit var api : APIInterface
lateinit var compositeDisposable: CompositeDisposable
internal lateinit var companyDialog : Dialog
internal lateinit var companyAdapter: CompanyAdapter
internal lateinit var data : List<Company>
fun showCompanyPopupView(){
companyDialog.setContentView(R.layout.compny_popup_screen)
val rvCompany : RecyclerView = companyDialog.findViewById(R.id.rvCompany)
rvCompany.setHasFixedSize(true)
rvCompany.layoutManager = LinearLayoutManager(this)
fetchData()
companyDialog.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
companyDialog.show()
}
private fun fetchData(){
val retrofit = APIClient.apIClient
if (retrofit != null) {
api = retrofit.create(APIInterface::class.java)
}
compositeDisposable.add(api.getCompanyData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe ({ companyList-> displayData(data)
},{
Toast.makeText(applicationContext, it.message, Toast.LENGTH_SHORT).show()
})
)
}
private fun displayData(companyList: List<Company>) {
val adapter = CompanyAdapter(this,companyList)
rvCompany.adapter = adapter
}
CompanyAdapter.kt
класс CompanyAdapter (внутренний контекст var: Context, внутренний var companyList: List): RecyclerView.Adapter () {переопределить fun onCreateViewHolder (p0: ViewGroup, p1: Int): CompanyViewHolder {TODO («не реализовано») // Для изменения тела созданных функций используйте File |Настройки |Шаблоны файлов.
val itemView = LayoutInflater.from(p0.context).inflate(R.layout.list_view_item,p0,false)
return CompanyViewHolder(itemView)
}
override fun getItemCount(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
return companyList?.size!!
}
override fun onBindViewHolder(p0: CompanyViewHolder, p1: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
// p0.rbButton.text = this!!.companyList?.get(p1)?.Cmp_Name
p0.bindModel(companyList[p1])
}
inner class CompanyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
val radioButton : RadioButton = itemView.findViewById(R.id.rbCompanyName)
fun bindModel(company: Company){
radioButton.text = company.Cmp_Name
}
}
}