Skip to content

Instantly share code, notes, and snippets.

@finnkvan
Created January 12, 2019 11:26
Show Gist options
  • Save finnkvan/c19706de7a03549bc229db06e8fa93d6 to your computer and use it in GitHub Desktop.
Save finnkvan/c19706de7a03549bc229db06e8fa93d6 to your computer and use it in GitHub Desktop.
class MainFragment : androidx.fragment.app.Fragment() {
companion object {
fun newInstance() = MainFragment()
}
private lateinit var viewModel: MainViewModel
private lateinit var message: TextView
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = inflater.inflate(R.layout.main_fragment, container, false)
message = view.findViewById(R.id.message)
return view
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
viewModel.pokeCharacteristic.observe(this, Observer { pokeCharacteristicResponse ->
message.text = pokeCharacteristicResponse.toString()
})
}
}
class MainViewModel : ViewModel() {
val pokeService = RetrofitClient().getRetrofit().create(PokeApi::class.java)
val pokeCharacteristic = pokeService.getCharacteristic(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment