android-livedata

How can I make it live data observer working based on user click event with take some user input, but should start observing from onCreate?

最后都变了- 提交于 2020-04-18 12:35:21
问题 I have retrofit then repository then view model and then view, but while clicking on button observer don't observe in onChanged. OnClicking on button from onClick, everything is working. I'm getting API response in logcat, but in onChanged it is not called! ManualLicenseKeyViewModel Code: public class ManualLicenseKeyViewModel extends ViewModel { public MutableLiveData<String> key = new MutableLiveData<>(); private MutableLiveData<License> mutableLiveData; private ManualLicenseRepository

How can I make it live data observer working based on user click event with take some user input, but should start observing from onCreate?

孤人 提交于 2020-04-18 12:35:10
问题 I have retrofit then repository then view model and then view, but while clicking on button observer don't observe in onChanged. OnClicking on button from onClick, everything is working. I'm getting API response in logcat, but in onChanged it is not called! ManualLicenseKeyViewModel Code: public class ManualLicenseKeyViewModel extends ViewModel { public MutableLiveData<String> key = new MutableLiveData<>(); private MutableLiveData<License> mutableLiveData; private ManualLicenseRepository

can I make a livedata observer in my viewmodel? or should I always observer in fragment/activity?

混江龙づ霸主 提交于 2020-04-18 05:31:43
问题 I am new to MVVM. so I have 2 requests to the server from my fragment/activity, the result from the first request will be used as an input parameter for the second request. so first in my fragment, when a button is clicked then I make a request to check whether the user is banned or not, if not then this user can create a post. so first I check if a user is banned or not using this code in my fragment class CreateEventFragment : Fragment() { lateinit var model: CreateEventViewModel override

can I make a livedata observer in my viewmodel? or should I always observer in fragment/activity?

自作多情 提交于 2020-04-18 05:29:40
问题 I am new to MVVM. so I have 2 requests to the server from my fragment/activity, the result from the first request will be used as an input parameter for the second request. so first in my fragment, when a button is clicked then I make a request to check whether the user is banned or not, if not then this user can create a post. so first I check if a user is banned or not using this code in my fragment class CreateEventFragment : Fragment() { lateinit var model: CreateEventViewModel override

why my map livedata is not called even though I have change the value?

此生再无相见时 提交于 2020-04-18 05:27:44
问题 I am new in MVVM and Android Architecture component. so I have repository like this object RestaurantRepository { val restaurants : LiveData<ArrayList<Restaurant>> = RestaurantClient.restaurants private var count : LiveData<Int> = Transformations.map(restaurants) { Log.d("debugLog","map") it.size } fun searchRestaurants(query: String, latitude:Double, longitude: Double) { mQuery = query RestaurantClient.searchRestaurants( query = query, latitude = latitude, longitude = longitude, start = 0 )

Share ViewModels between fragments OR share LiveData between ViewModels

一个人想着一个人 提交于 2020-04-18 03:50:58
问题 Basically I want a way to properly share ViewModels between fragments OR share LiveData between ViewModels. My scenario: I have 2 fragments ( FragmentA & FragmentB ) - each has its own ViewModels: FragmentA has ViewModelA , FragmentB has ViewModelB . ViewModelA has LiveDataA1 , ViewModelB has LiveDataB1 and LiveDataB2 ViewModelB is only allowed to have LiveDataB2 and ViewModelA cannot have it. Problem is I want FragmentA to observe LiveDataB2 from ViewModelB . Approach#1: Aside from

Insert on Room DB does not trigger Observer on Activity

与世无争的帅哥 提交于 2020-04-17 22:14:54
问题 In my activity i have an Observer that observes this query @Query("""Select *, (Select account_id from accounts where account_id = from_account_id) as contact_account_id, (Select first_name from accounts where account_id = from_account_id) as contact_first_name, (Select last_name from accounts where account_id = from_account_id) as contact_last_name from messages inner join messageQueue on messages.client_message_id = messagequeue.client_message_id where ((msg_type = 1 and body <> "") or msg

Insert on Room DB does not trigger Observer on Activity

丶灬走出姿态 提交于 2020-04-17 22:14:22
问题 In my activity i have an Observer that observes this query @Query("""Select *, (Select account_id from accounts where account_id = from_account_id) as contact_account_id, (Select first_name from accounts where account_id = from_account_id) as contact_first_name, (Select last_name from accounts where account_id = from_account_id) as contact_last_name from messages inner join messageQueue on messages.client_message_id = messagequeue.client_message_id where ((msg_type = 1 and body <> "") or msg

Insert on Room DB does not trigger Observer on Activity

我的未来我决定 提交于 2020-04-17 22:14:01
问题 In my activity i have an Observer that observes this query @Query("""Select *, (Select account_id from accounts where account_id = from_account_id) as contact_account_id, (Select first_name from accounts where account_id = from_account_id) as contact_first_name, (Select last_name from accounts where account_id = from_account_id) as contact_last_name from messages inner join messageQueue on messages.client_message_id = messagequeue.client_message_id where ((msg_type = 1 and body <> "") or msg

Some fragment observers trigger after pop from back stack although data is not changed

假装没事ソ 提交于 2020-04-17 21:34:19
问题 I have some problem in nested fragment in Kotlin. I have nested fragment with ViewModel. After resuming fragment from back button press all observers on viewModel LiveData triggers again although my data does not changed. First i googled and tried for define observer in filed variable and check if it is initialized then do not observer it again: lateinit var observer: Observer fun method(){ if (::observer.isInitialized) return observer = Observer{ ... } viewModel.x_live_data.observe