android-livedata

Google SignInButton's onClick doesn't work using DataBinding

荒凉一梦 提交于 2019-12-11 18:56:37
问题 When I try to set the onClick method in my Google's SignInButton : android:onClick="@{() -> viewModel.onGoogleLoginClick()}" I always get this error: Found data binding errors. ****/ data binding error ****msg:Cannot find the proper callback class for android:onClick. Tried android.view.View but it has 0 abstract methods, should have 1 abstract methods. file:/Users/user/Android/project/app/src/main/res/layout/activity_login.xml loc:53:31 - 53:66 ****\ data binding error **** Here is my code:

Data binding - access individual properties contained in LiveData

半世苍凉 提交于 2019-12-11 15:42:58
问题 Is there a way to do something like this with LiveData and data binding? ViewModel has this property: val weather: LiveData<UnitSpecificCurrentWeatherEntry> What I'm trying to do in the layout: <TextView android:id="@+id/textView" android:text="@{viewmodel.weather.value.someProperty}"... /> Is this possible in any way or do I have to split the object contained in LiveData into multiple ones for each property of the contained object? 回答1: From the point of view of MVVM pattern it's not

Are LiveData objects observable in XML?

删除回忆录丶 提交于 2019-12-11 15:37:50
问题 When I bind ObservableField<> objects to a view in XML, changes to the value via set() are immediately reflected in the view. When I bind LiveData<> objects in XML, however, the initial value is rendered but changes via value= have no effect on the view. They are passed to Kotlin observers. I assumed LiveData would work like Observable* classes in XML bindings. Is that not the case? If I need to observe a value in both XML and Kotlin, do I really need to create two observables? 回答1: You can

Retrofit Observable response to LiveData object using subscribe

微笑、不失礼 提交于 2019-12-11 15:13:00
问题 I have inherited this project that was using retrofit incorrectly with LiveData by trying to convert responses to LiveData immediately. I am in the middle of trying to refactor, but am getting stuck with converting an RxJava Observable to a LiveData object in the ViewModel. Here is what I have so far: Retrofit Service interface Service { @POST("user/login") fun postLogin(@Body body: LoginBody) Observable<ApiResponseWrapper<LoginRemote>> } As you can see, Observable wraps an ApiResponseWrapper

how to retrieve list of objects from dao via LiveData<> in View Model when there is no change to trigger onChange method in View Model in android

半腔热情 提交于 2019-12-11 14:30:07
问题 I am using android studios to build a dictionary app. Everything has went fairly well with help from the SO community and now I have another question. I have setup several custom dictionaries so that the user can store and view words in different dictionaries. (e.g. literature, programming, general, etc.) These will be a FK id in the word entity and filled when the user adds new words. In the MainActivity, I have an Options menu item for 'Change Dictionary'. This brings up an AlertDialog

Fragment not receiving LiveData updates after remove + add

China☆狼群 提交于 2019-12-11 11:55:12
问题 I am currently playing around to get a hang of the fragment 's lifecycle in relation to ViewModel and LiveData . I have 2 fragments , fragmentA and fragmentB . I add the Observer in the onCreate method of each fragment . @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedViewModel = ViewModelProviders.of(getActivity()).get(SharedViewModel.class); sharedViewModel.getText().observe(this, new Observer<CharSequence>() { @Override public

Create ViewModel with Application

百般思念 提交于 2019-12-11 07:58:56
问题 I am trying to set data onto the ViewModel in a file in which I do not wish to hold any activity references. Class A -> set data onto the LiveData in ViewModel Has an Application class reference but does not hold activity or fragment Class B -> read data from the LiveData in ViewModel Has a reference to the activity. Class B can be destroyed and recreated along with the Activity's config changes. Class A is persistent in memory and keeps setting data to the LiveData Problem:

How to get LiveData from Room?

我的梦境 提交于 2019-12-11 06:47:36
问题 I'm trying to get LiveData from Room. So my RecycleView can have Live updates if anything in database is changed I have tried with out LiveData and that works, but when i add LiveData that always shows this error. error: Not sure how to convert a Cursor to this method's return type (androidx.lifecycle.LiveData<java.util.List<com.example.models.Club>>). public abstract java.lang.Object getAll(@org.jetbrains.annotations.NotNull() I googled and looked on this site for solution, but every on with

Android LiveData List not updating

一个人想着一个人 提交于 2019-12-11 06:39:28
问题 I am using Android LiveData and Room Database to update a list. I have a list of notes which have a tick to mark them as "DONE". If they are marked done, I remove them from current list (not from database) so that they can be shown on another page. But marking them done does not update my list. DAO: @Dao public interface NoteDao { @Query("SELECT * FROM notes WHERE isDone=0") LiveData<List<Note>> getAll(); @Insert void insert(Note note); @Delete void delete(Note note); @Update void update(Note

Dao method returns List<String> while I need a Map<String,Integer>

♀尐吖头ヾ 提交于 2019-12-10 21:56:48
问题 In an Android app using Architecture Components I have the following view model: public class MainViewModel extends AndroidViewModel { private final MutableLiveData<List<String>> mUnchecked = new MutableLiveData<>(); private LiveData<List<String>> mChecked; public void setUnchecked(List<String> list) { mUnchecked.setValue(list); } public LiveData<List<String>> getChecked() { // OBSERVED BY A FRAGMENT return mChecked; } public MainViewModel(Application app) { super(app); mChecked =