Category : android-livedata

In Activity I have this method, which is called when I click on item. It calls the removePerson() method from the ViewModel. @Override public void onItemClick(int position) { myRecyclerViewModel.removePerson(myRecyclerAdapter.getPersonAt(position)); myRecyclerViewModel.addNewPerson(/*some new Person which I dont understant how to pull here from Single<List<Person mPerson from ViewModel ocasionally*/) } But I need so that onItemClick not only ..

Read more

I have this value: val communicationIsExpanded = ObservableField<Boolean>(false) I have a LiveDataObserver, set on a ViewModel item. And I have this implementation on property changed: private inner class OnPropertyChangedCallbackImpl : Observable.OnPropertyChangedCallback() { override fun onPropertyChanged(sender: Observable, propertyId: Int) { renderChange() } } fun renderChange() { communicationIsExpanded.set(communication?.isExpanded) } But whenever my list is initialised, for a ..

Read more

When I click on an item, OnItemListener.onItemClick (see in Adapter code) works, and remove the respective from LiveData<List> mListLivedata (see in ViewModel). The problem is that this doesn’t update recyclerView, despite the fact that there is an Observer which subscribes on this LiveData. There is still 4 views in recyclerView, but if if I click ..

Read more

I have complex and generic RecyclerView design and List Adapter. override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder { val layoutInflater: LayoutInflater = LayoutInflater.from(parent.context) val binding: ViewDataBinding = DataBindingUtil.inflate(layoutInflater, viewType, parent, false) return object : BaseViewHolder(binding) { override fun bindData(position: Int) { val model = getItem(position).data itemBinding.setVariable(BR.model, model) viewModel?.let { itemBinding.setVariable(BR.viewModel, it) } } } } ..

Read more

I was trying to implement SignIn feature in a fragment. Following is the code for that: @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { MainViewModel mainViewModel = new ViewModelProvider(requireActivity()).get(MainViewModel.class); String email = ….; String password = ….; SignInLiveData signInStatusObserver = mainViewModel.getSignInStatusLiveData(email, password); signInStatusObserver.observe(getViewLifeCycleOwer(), new Observer<Boolean>{ @Override public void onChanged(Boolean isSignedIn) { if(isSignedIn) Toast.makeText(requireContext(), ..

Read more