-3
I want to pass data from one Ragment to another, but the code works but does not pass the data. Someone can help me in this?
I wish to go from ListaPokemonsFragment
for DetalhesPokemonFragment
ListaPokemonsFragment
:
// acao de ir para os detalhes do pokemon clicado
private fun goToDetalhes(pokemon: PokemonItem){
val direcao = ListaPokemonsFragmentDirections
.actionListaPokemonsToDetalhesPokemons(pokemon)
controlador.navigate(direcao)
}
DetalhesPokemonFragment
private fun configDetalhes() {
viewModel.getDetalhes(pokemon.id)
viewModel.mResponse.observe(viewLifecycleOwner, {
if(it.isSuccessful){
tv_detalhes_nome_pokemon.text = it.body()?.nome
}
})
}
navigation:
<fragment
android:id="@+id/detalhesPokemons"
tools:layout="@layout/detalhes_pokemon"
android:name="com.example.pokedex.ui.detalhesPokemons.DetalhesPokemonsFragment"
android:label="Detalhes Pokemons" >
<argument
android:name="pokemon"
app:argType="com.example.pokedex.model.PokemonItem" />
</fragment>
when I create onCreate, it’s not getting the "pokemonItem"
– Matheus Finamor
@Matheusfinamor did you serialize the object? The answer is very clear, I tested it here myself and it worked
– Diogo
Yes, I solved the problem, it was giving error with my Database. I’m still not doing the data persistence but had already left the database ready, with it ready was giving a conflict with my "Pokemonitem". Delete my Database class and it worked normally. Thank you
– Matheus Finamor