From past two days, I am trying to set recycler view values received from Eventbus but getting error No adapter attached; skipping layout. I have tried and tested every code that is available on internet like 1. https://github.com/gunhansancar/eventbus-example appended data in adapter 2. Trying to impact RecyclerView items via EventBus - creating method in adapter class but still nothing is happening
I am getting response in event but cannot use that response in recycler view
code
@Subscribe(threadMode = ThreadMode.MAIN)
fun pickDropChooseEvent (data : PickAddressDone){
try {
//vehicle list result is a model
vehicleListResult = data.vehicleListResult
vehicleAdapter.updateData(vehicleListResult.vehicleCategory!!);
vehicleAdapter.notifyDataSetChanged();
}
catch (exception : Exception )
{
Log.d("vehicle info" ,"catch pick drop "+exception.toString())
}
}
then in ViewCreated I have declared a method "initMembers" to initialise views of the fragment
private fun initMembers() {
try{
vehicleList = ArrayList()
vehicleList.addAll(vehicleListResponse.vehicleListResult!!.vehicleCategory!!)
tvDistance.text = vehicleListResult.ride!!.distanceText
rvVehicleList.setHasFixedSize(true)
rvVehicleList.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
rvVehicleList.setAdapter(vehicleAdapter)
vehicleAdapter = VehicleCategoryAdapter(context!!, vehicleList)
// i have even tried notify change
}catch (exception: Exception)
{
Log.d("vehicle info", " exception "+exception)
}
}
Update: It is resolved there was no issue in the code but issue was in the Xml ConstraintLayout..
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="@dimen/margin_2dp"
android:background="@drawable/grey_shadow_background"
app:layout_constraintBottom_toTopOf="@+id/clRideInfo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintTop_toTopOf="parent" // this was causing the issue as height was not assigned to the constraint view. Recycler view is showing after removing it
app:layout_constraintStart_toStartOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvVehicleList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/layout_vehiclelist_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
Thank you everyone