Guest User

Untitled

a guest
Dec 18th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package com.example.gabriel.mediatorlivedata
  2.  
  3. import android.arch.lifecycle.LiveData
  4. import android.arch.lifecycle.MediatorLiveData
  5. import android.arch.lifecycle.MutableLiveData
  6. import android.os.Handler
  7. import android.util.Log
  8. import java.util.*
  9.  
  10.  
  11. class ApiClass {
  12.  
  13. val list = listOf("Gabriel", "Miguel")
  14.  
  15. fun getApi() : LiveData<List<String>>{
  16. val mutableLiveData = MutableLiveData<List<String>>()
  17. mutableLiveData.value = Collections.emptyList()
  18.  
  19. Handler().postDelayed({ mutableLiveData.value = list }, 3000)
  20.  
  21. return mutableLiveData
  22. }
  23.  
  24.  
  25. }
  26.  
  27. class Caller {
  28.  
  29. fun caller() : MediatorLiveData<List<String>>{
  30. val apiClass = ApiClass()
  31. val mediatorLiveData = MediatorLiveData<List<String>>()
  32.  
  33. mediatorLiveData.addSource(apiClass.getApi(), { Log.i("myTag", "Works") })
  34. return mediatorLiveData
  35. }
  36.  
  37. }
Add Comment
Please, Sign In to add comment