android-mvvm

I can auto increment id in room database but when refresh database it's shows double

蹲街弑〆低调 提交于 2021-02-13 12:58:47
问题 In my app firstly i am fetching data from server using retrofit then it's saved in room database table then it shows in recyclerview but when i using a id as a primary key it's show only one data then this id i annotat autoGenerate = true then it's show all data which i put in server but when i reopen my app,it's show double data(this mean firstly i have 3 data in server,this app show 3 data but when i reopen or refresh my database it's show 6 data ,every time in refresh it's increasing).but

I can auto increment id in room database but when refresh database it's shows double

旧街凉风 提交于 2021-02-13 12:56:51
问题 In my app firstly i am fetching data from server using retrofit then it's saved in room database table then it shows in recyclerview but when i using a id as a primary key it's show only one data then this id i annotat autoGenerate = true then it's show all data which i put in server but when i reopen my app,it's show double data(this mean firstly i have 3 data in server,this app show 3 data but when i reopen or refresh my database it's show 6 data ,every time in refresh it's increasing).but

I can auto increment id in room database but when refresh database it's shows double

核能气质少年 提交于 2021-02-13 12:54:16
问题 In my app firstly i am fetching data from server using retrofit then it's saved in room database table then it shows in recyclerview but when i using a id as a primary key it's show only one data then this id i annotat autoGenerate = true then it's show all data which i put in server but when i reopen my app,it's show double data(this mean firstly i have 3 data in server,this app show 3 data but when i reopen or refresh my database it's show 6 data ,every time in refresh it's increasing).but

Android LiveData: Transformation switchMap: Apply filter on the original list and show the filtered data

泪湿孤枕 提交于 2021-02-11 16:51:27
问题 public class FlightViewModel extends BaseViewModel { private FlightRepository flightRepository; private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mSearchFlights = new MediatorLiveData<>(); private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mOriginalList = new MediatorLiveData<>(); private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mSortedSearchFlights = new MediatorLiveData<>(); public FlightViewModel(@NonNull Application application) { super(application);

How to databind livedata object (android)

感情迁移 提交于 2021-02-08 09:56:50
问题 Today I've some question about mvvm and databinding on android, I'm trying to bind object properties on view. I've an Object (Model) with some properties, by example : public String name; public String title; public int value; I've a ViewModel with livedata like this : MutableLiveData<Object> _obj = new MutableLiveData<>(); public LiveData<Object> obj = _obj; And, at last, I've a view like this : <layout> <data> <variable name="viewModel"> type="com.sample.app.viewmodels.MainViewModel" /> <

How to use app:items=“@{viewModel.items}” attribute with RecyclerView, MVVM and data binding?

寵の児 提交于 2021-01-29 08:55:31
问题 There is an app:items="" attribute for RecyclerView, how is this attribute used with MVVM and android.arch.lifecycle.ViewModel , not ViewModel that extends BaseObservable? items could be LiveData, List or ObservableArrayList, with which collection should it be used? 来源: https://stackoverflow.com/questions/51078439/how-to-use-appitems-viewmodel-items-attribute-with-recyclerview-mvvm-and

The class cannot inherit from the AndroidViewModel, why?

孤街醉人 提交于 2021-01-29 02:57:18
问题 I try create a new class that inherits from AndroidViewModel, like this public class LoginViewModel extends AndroidViewModel { public LoginViewModel() {} ... But I get this message in the ide: There is no default constructor available in 'android.arch.lifecycle.AndroidViewModel' My happen this? My graddle looks like this: ... implementation 'android.arch.lifecycle:extensions:1.1.1' ... Any idea? Thanks 回答1: You will need to add super call to AndroidViewModel class when inheriting from it.

Android viewModel savedStateHandle

落爺英雄遲暮 提交于 2021-01-27 21:09:27
问题 This is more of a conceptual question. Android recently introduced the concept of handling the state during process death inside viewModel rather than savedInstanceState which previously used to be in Activity or Fragment. My question is how do I test this process death? If I rightly understand the documentation, the Process death happens to be Android killing the app due to full memory when app is no longer used in background. Also will the viewModel save the state when user kills the app

How to set click listener and pass edittext fields value to view model using data binding

喜夏-厌秋 提交于 2021-01-21 07:24:11
问题 Hi I am trying to use data binding and mvvm architecture in my android app. I want to add click listener using data binding in the layout and send the values of username and password edittext to the view model and it will execute the web service and call appropriate method of LoginActivity like startHomeActivity() . Does anyone know how to do this or Am I taking wrong approach ? I have below snippet of code of my activity, layout and view model LoginActivity.kt class LoginActivity :