Created
December 24, 2017 16:35
-
-
Save prakashpun/4cf6bc58317eba4a74f2ea8d1ab6c05f 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
public class MainActivity extends AppCompatActivity { | |
private CustomAdapter adapter; | |
private RecyclerView recyclerView; | |
ProgressDialog progressDoalog; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
progressDoalog = new ProgressDialog(MainActivity.this); | |
progressDoalog.setMessage("Loading...."); | |
progressDoalog.show(); | |
/*Create handle for the RetrofitInstance interface*/ | |
GetDataService service = RetrofitClientInstance.getRetrofitInstance().create(GetDataService.class); | |
Call<List<RetroPhoto>> call = service.getAllPhotos(); | |
call.enqueue(new Callback<List<RetroPhoto>>() { | |
@Override | |
public void onResponse(Call<List<RetroPhoto>> call, Response<List<RetroPhoto>> response) { | |
progressDoalog.dismiss(); | |
generateDataList(response.body()); | |
} | |
@Override | |
public void onFailure(Call<List<RetroPhoto>> call, Throwable t) { | |
progressDoalog.dismiss(); | |
Toast.makeText(MainActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
/*Method to generate List of data using RecyclerView with custom adapter*/ | |
private void generateDataList(List<RetroPhoto> photoList) { | |
recyclerView = findViewById(R.id.customRecyclerView); | |
adapter = new CustomAdapter(this,photoList); | |
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(MainActivity.this); | |
recyclerView.setLayoutManager(layoutManager); | |
recyclerView.setAdapter(adapter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment