Created
January 12, 2019 11:26
-
-
Save finnkvan/c19706de7a03549bc229db06e8fa93d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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