Created
October 19, 2016 05:32
-
-
Save juanxodj/841e64f3216b88a09c680056f406e9e1 to your computer and use it in GitHub Desktop.
This file contains 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
package com.lctics.retrofit2; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.widget.Button; | |
import android.widget.TextView; | |
import com.lctics.retrofit2.dataPokemon.model.PokemonFeed; | |
import com.lctics.retrofit2.dataPokemon.remote.PokemonAPI; | |
import butterknife.BindView; | |
import butterknife.ButterKnife; | |
import butterknife.OnClick; | |
import retrofit2.Call; | |
import retrofit2.Callback; | |
import retrofit2.Response; | |
public class Pokemon extends AppCompatActivity { | |
private static final String TAG = "MyActivity"; | |
@BindView(R.id.txtID) TextView txtID; | |
@BindView(R.id.txtName) TextView txtName; | |
@BindView(R.id.txtSpecie) TextView txtSpecie; | |
@BindView(R.id.btnLeer) Button btnLeer; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_pokemon); | |
ButterKnife.bind(this); | |
} | |
@OnClick(R.id.btnLeer) public void buttonRefresh(){ | |
PokemonAPI.Factory.getInstance().getPokemon().enqueue(new Callback<PokemonFeed>() { | |
@Override | |
public void onResponse(Call<PokemonFeed> call, Response<PokemonFeed> response) { | |
Log.e(TAG, "ID: " + response.body().getNationalId()); | |
txtID.setText("00"+response.body().getNationalId()); | |
txtName.setText(response.body().getName()); | |
txtSpecie.setText(response.body().getSpecies()); | |
} | |
@Override | |
public void onFailure(Call<PokemonFeed> call, Throwable t) { | |
Log.e("Failed",t.getMessage()); | |
} | |
}); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
buttonRefresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment