Category : android-viewmodel

I have a ViewModel that access a List of object of LiveData and i want to assign my variable to that list. Here is the code. chatViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(ChatViewModel.class); chatViewModel.getAllContactsForChat().observe(this, new Observer<List<UserContacts>>() { @Override public void onChanged(List<UserContacts> userContacts) { Toast.makeText(ChatActivity.this, "inside", Toast.LENGTH_SHORT).show(); for(int i = 0; i<userContacts.size(); i++) { UserContacts user = userContacts.get(i); ..

Read more

I don’t know how to properly split code to separate views/viewmodel in android CRUD application. The items are stored in database and accessed using GreenDao. I have FragmentA with recyclerView which display all items from database (their names). I have FragmentB which is opened when user click RecyclerView row and contains details of the item. ..

Read more

I implemented SelectionTracker for RecycleView and it works fine until I navigate to another fragment and press the back button. After navigation, it stops working correctly and after selection I can’t deselect item anymore. I created a sample project on github and I can reproduce bug there: https://github.com/alborozd/RecycleViewSelectionProblem Here is my code from that sample ..

Read more

My Fragment: class FirstFragment : Fragment() { private lateinit var binding: FragmentFirstBinding private lateinit var viewModelFactory: FirstViewModelFactory private lateinit var viewModel: FirstViewModel override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { binding = DataBindingUtil.inflate(inflater, R.layout.fragment_first, container, false) viewModelFactory = FirstViewModelFactory(requireActivity().application, this.lifecycle) //<- Lifecycle object viewModel = ViewModelProvider(this, viewModelFactory).get(FirstViewModel::class.java) return binding.root } } My ViewModel: ..

Read more

Error: error: [Dagger/MissingBinding] java.util.ArrayList<java.lang.Integer> cannot be provided without an @Inject constructor or an @Provides-annotated method. public abstract static class SingletonC implements HiltWrapper_ActivityRetainedComponentManager_LifecycleComponentBuilderEntryPoint, javax.inject.Provider<java.util.ArrayList<java.lang.Integer>> is injected at space.rodionov.swedishdriller.DrillerViewModel_AssistedFactory(�, drillerCatList, �) space.rodionov.swedishdriller.DrillerViewModel_AssistedFactory is injected at space.rodionov.swedishdriller.DrillerViewModel_HiltModule.bind(factory) java.util.Map<java.lang.String,javax.inject.Provider<androidx.hilt.lifecycle.ViewModelAssistedFactory<? extends androidx.lifecycle.ViewModel>>> is injected at androidx.hilt.lifecycle.ViewModelFactoryModules.ActivityModule.provideFactory(�, viewModelFactories) @dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory java.util.Set<androidx.lifecycle.ViewModelProvider.Factory> is requested at dagger.hilt.android.internal.lifecycle.DefaultViewModelFactories.ActivityEntryPoint.getActivityViewModelFactory() [space.rodionov.swedishdriller.SwedishDrillerApplication_HiltComponents.SingletonC ? space.rodionov.swedishdriller.SwedishDrillerApplication_HiltComponents.ActivityRetainedC ? space.rodionov.swedishdriller.SwedishDrillerApplication_HiltComponents.ActivityC] The following ..

Read more

In ViewModel: val drillerCatList: List<Int> = emptyList() val shownCategoriesFlow = wordDao.getShownCategories() // which returns type Flow<List<CategoryItem>> Catigory object: data class CategoryItem( val categoryName: String, val categoryNumber: Int, val categoryShown: Boolean = false, @PrimaryKey(autoGenerate = true) var id: Int = 0 ) : Parcelable { } How can I retrieve all categoryNumber values from shownCategoriesFlow: FLow<List> ..

Read more

I have 2 fragments, FragmentA contains a list of starwar characters whereas FragmentB contains details of that character. I am using viewModelScope.launch in my fragments to fetch details for a character. Below is my ViewModel @HiltViewModel class DetailsViewModel @Inject constructor( private val getSpecieDetailsUseCase: GetSpecieDetailsUseCase, private val getFilmDetailsUseCase: GetFilmDetailsUseCase, private val getPlanetDetailsUseCase: GetPlanetDetailsUseCase, private val mapper: ..

Read more

I want to validate form login Kotlin with Application Structure Model–view–viewmodel I used ViewModel with Data Binding and LiveData, Create a variable in the XML file for Two-Way Data I can validate when empty field but I don’t know How to set error for editText when user change EditText invited format or characters worng activity_main.xml ..

Read more