Skip to content

Instantly share code, notes, and snippets.

@kohendrix
Created February 2, 2019 03:29
Show Gist options
  • Select an option

  • Save kohendrix/caa9f1a75e486db1a0c4fc894cdedbb3 to your computer and use it in GitHub Desktop.

Select an option

Save kohendrix/caa9f1a75e486db1a0c4fc894cdedbb3 to your computer and use it in GitHub Desktop.
TwitterSample search() updated
class MainViewModel : ViewModel() {
private val repository = TweetsRepository()
private val searchWords = MutableLiveData<String>() // trigger
// tweet data exposed to Views
val tweetDataResults: LiveData<TweetDataResult>
= Transformations.switchMap(searchWords) { str -> repository.loadTweets(str) }
/**
* search trigger
*/
fun search(str: String) {
Log.d(TAG, "search $str")
searchWords.value = str
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment