android-mvvm

Two way binding cannot resolve a setter

℡╲_俬逩灬. 提交于 2020-05-15 11:13:47
问题 I am trying to learn about data binding I have my CreditCardViewModel class which is bind in my fragment as follows public class CreditCardValidatorFragment extends Fragment { private CreditCardViewModel cardViewModel; private CcValidateFragmentBinding binding; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = DataBindingUtil.inflate(inflater, R.layout.cc_validate_fragment, container,

Two way binding cannot resolve a setter

独自空忆成欢 提交于 2020-05-15 11:10:56
问题 I am trying to learn about data binding I have my CreditCardViewModel class which is bind in my fragment as follows public class CreditCardValidatorFragment extends Fragment { private CreditCardViewModel cardViewModel; private CcValidateFragmentBinding binding; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = DataBindingUtil.inflate(inflater, R.layout.cc_validate_fragment, container,

Cannot resolve ViewModelProvider construction in a fragment?

蹲街弑〆低调 提交于 2020-05-13 06:09:27
问题 I have been spending a lot of time trying to figure out why in the code below (towards the end), I get an error on ViewModelProvider(this). I also tried getActivity() instead of 'this', same issue. The error I get is "Cannot resolve constructor ..." import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; public class ItemSetupFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

Cannot resolve ViewModelProvider construction in a fragment?

浪尽此生 提交于 2020-05-13 06:08:07
问题 I have been spending a lot of time trying to figure out why in the code below (towards the end), I get an error on ViewModelProvider(this). I also tried getActivity() instead of 'this', same issue. The error I get is "Cannot resolve constructor ..." import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; public class ItemSetupFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

LiveData Object keeps being null after getValue() is called

╄→гoц情女王★ 提交于 2020-04-10 09:19:34
问题 I want to update a member variable of an object inside my Repository on a LiveData- Object. The problem is, that if I call the getValue() Method, I keep getting an NullPointerException, although the value does exist inside my Room- Library. My question now is, how do I get the value from the LiveData Object without calling the observe() Method? (I am not able to call the observe method inside my repository, cause that method wants me to enter a LifeCycleOwner- reference, which is not present

LiveData Object keeps being null after getValue() is called

不羁的心 提交于 2020-04-10 09:16:20
问题 I want to update a member variable of an object inside my Repository on a LiveData- Object. The problem is, that if I call the getValue() Method, I keep getting an NullPointerException, although the value does exist inside my Room- Library. My question now is, how do I get the value from the LiveData Object without calling the observe() Method? (I am not able to call the observe method inside my repository, cause that method wants me to enter a LifeCycleOwner- reference, which is not present

Databinding Recyclerview and onClick

Deadly 提交于 2020-03-26 03:19:26
问题 Ok I'll try one more time. Last time I asked about passing data between recyclerview and item and one person helped me with open item by click, but I still don't have idea how to show the data of clicked item in new activity. I want to click on an item and then display the data of that item in new activity. In this activity I want to edit data. Does anyone knows how to do it? I need any idea. RecyclerView Adapter with OnItemClickListener interface: public class RecyclerViewAdapter extends

Do we really need viewModelFactories and viewmodelProviders when using Dagger?

橙三吉。 提交于 2020-03-05 03:11:08
问题 So I was working on some sample MVVM project using Dagger. I have a viewmodel factory that goes like this: class DaggerViewModelFactory @Inject constructor(private val viewModelsMap: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>) : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { val creator = viewModelsMap[modelClass] ?: viewModelsMap.asIterable().firstOrNull { modelClass.isAssignableFrom(it.key) }?.value ?: throw

In Android, if I use binding, how to apply ClickableSpan?

℡╲_俬逩灬. 提交于 2019-12-25 01:35:49
问题 I know that if binding is not applied, then I can use Textview.setText(ClickableSpan) to apply spannig effect to make part of the text clickable. However, my app used binding and the textview's text is binded to a ViewModel inside xml like android:text="@{model.certainString}" and in the ViewModel I declared String certainString = "" , in this case how do I apply spanning inside the ViewModel then? 回答1: You could write your own BindingAdapter which accepts either the model or the string value

Not able to import InstantTaskExecutorRule in my 'jUnit' test case even after adding 'core-testing' dependency - Android testing

纵然是瞬间 提交于 2019-12-24 03:42:53
问题 I am writing test cases for my LoginViewModel . Where I want to perform setValue() operation on my MutableLiveData . To avoid Method getMainLooper in android.os.Looper not mocked Exception I am trying to add the following Rule in my ViewModel file inside test folder . @Rule public InstantTaskExecutorRule mInstantTaskExecutorRule = new InstantTaskExecutorRule(); for that, I have added the following dependency: androidTestImplementation 'android.arch.core:core-testing:1.1.1' as dependency. But