Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.retrofitgitexample.ui.adapter;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.widget.ListView;
- import android.widget.Toast;
- import com.example.retrofitgitexample.R;
- import com.example.retrofitgitexample.api.model.GitHubRepo;
- import com.example.retrofitgitexample.service.GitHubClient;
- import java.util.List;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Response;
- import retrofit2.Retrofit;
- import retrofit2.converter.gson.GsonConverterFactory;
- public class MainActivity extends AppCompatActivity {
- private ListView listview;
- public static final String TAG = "MainActivityLog";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- listview = findViewById(R.id.pagination_list);
- Retrofit.Builder builder = new Retrofit.Builder()
- .baseUrl("https://api.github.com/")
- .addConverterFactory(GsonConverterFactory.create());
- Retrofit retrofit = builder.build();
- GitHubClient client = retrofit.create(GitHubClient.class);
- Call<List<GitHubRepo>> call = client.reposForUser("fs-opensource");
- call.enqueue(new Callback<List<GitHubRepo>>() {
- @Override
- public void onResponse(Call<List<GitHubRepo>> call, Response<List<GitHubRepo>> response) {
- List<GitHubRepo> repos = response.body();
- Log.d(TAG, "onResponse: " + repos);
- // listview.setAdapter(new GitHubRepoAdapter(MainActivity.this, repos));
- }
- @Override
- public void onFailure(Call<List<GitHubRepo>> call, Throwable t) {
- Toast.makeText(MainActivity.this, "Error", Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement