Categories
Mastering Development

How to set LiveData from Adapter?

I have two fragments: (1) Library Fragment, (2) Book Fragment The library fragments displays all available books via a RecyclerView. The user can tab on each of the RecyclerView Items, which will set the LiveData to the corresponding book. At the same time the Book Fragment will be opened and the contents of that book […]

Categories
Mastering Development

Recycler View not displaying the list

My recyclerview is not working and doesn’t display the list I’m setting to it. Could you help me find out the problem ? Below are the Fragment and the Adapter that I’ve created. Fragment Class -> class HomeFragment : Fragment() { lateinit var recyclerViewHomeHome: RecyclerView lateinit var layoutManager: RecyclerView.LayoutManager private val restaurantsInfoList = arrayListOf<Restaurant>( Restaurant(“rohh”, […]

Categories
Mastering Development

java.lang.IllegalStateException: pb must not be null at TopHeadlinesFragment?

I am developing news app and I have implemented livedata with progress bar but I am getting following exception in my code java.lang.IllegalStateException: pb must not be null at yodgorbek.komilov.musobaqayangiliklari.ui.TopHeadlinesFragment$initViewModel$2.onChanged(TopHeadlinesFragment.kt:60) at yodgorbek.komilov.musobaqayangiliklari.ui.TopHeadlinesFragment$initViewModel$2.onChanged(TopHeadlinesFragment.kt:22) at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131) at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:144) at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:442) at androidx.lifecycle.LiveData$LifecycleBoundObserver.onStateChanged(LiveData.java:394) at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361) at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300) at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339) at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145) at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131) at androidx.fragment.app.Fragment.performStart(Fragment.java:2637) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:915) at […]

Categories
Mastering Development

how to binding correctly recyclerview items in kotlin?

I am developing a news app and I am following MVVM with data binding in recycler view I am trying to bind items but I am just stuck below my recyclerview items xml file <?xml version=”1.0″ encoding=”utf-8″?> <layout> <data> <variable name=”article” type=”yodgorbek.komilov.musobaqayangiliklari.model.Article”> </variable> </data> <androidx.cardview.widget.CardView xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”wrap_content”> <RelativeLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_marginTop=”16dp” android:layout_marginBottom=”16dp”> <ImageView […]

Categories
Development

My Adapter seems to be receiving data, but it’s not being displayed in my RecyclerView. Any ideas as to what I am doing wrong?

So, I’ve been debugging for a while, and I can’t seem to find where my error is. On my Debug console it shows the size of item list I am receiving from the response, with the data associated with each item in the list. It also shows the id of the textviews I set on […]

Categories
Development

findContainingViewHolder returns null

In the following application, you have basically 2 fragments: 1) a food database, 2) a consumed food list 1) the user can manually add foods with the corresponding macronutrient information (kcal, carbs, protein, etc.). The data is stored in a SQL database via Room and is being observed via LiveData 2) a fragment (FoodDiaryFragment.kt) that […]

Categories
Development

LiveData doesn’t update data

I would like to ask you for help. I am writing an application that uses MVVM and LiveData architecture. Inside ViewPager I have 3 fragments displaying data that comes from ViewModel. And I noticed that after connecting the viewModel to the activity and to the fragment, the data is updated only when the activity is […]

Categories
Development

Creating a simple Android fragment with Navigation Drawer

I’m an experienced developer, but new to Android programming, and I’m a bit stumped. I started off with the Android Studio Navigation Drawer standard project template. I managed to implement a simple list of items in one of the fragments (Gallery Fragment), and do something when a button is pressed. So when the button is […]

Categories
Development

lateinit property value assigned but i face kotlin.UninitializedPropertyAccessException in Kotlin

I have assigned value for a lateinit variable in Kotlin when creating instance for fragment, Then i used the variable in fragment’s oncreateview method. It works perfectly, but sometime it return kotlin.UninitializedPropertyAccessException and my application was closed. I don’t know when it occurred, i have checked multiple scenarios. but it never works. Here i added […]

Categories
Development

Data binding memory leak

When I open my fragment that used data binding, memory leak occur as shown in below. Is there any appropriate answer to solve this? I used Data binding Navigation Lifecycle Material ui ┬─── │ GC Root: System class │ ├─ androidx.databinding.ViewDataBinding class │ Leaking: NO (a class is never leaking) │ ↓ static ViewDataBinding.sReferenceQueue │ […]