Created
July 25, 2020 11:45
-
-
Save firdaus1453/7887a3f10e29d4e1eed89e3580c3d852 to your computer and use it in GitHub Desktop.
MainActivity.java
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
| package me.firdaus1453.crudapi; | |
| import android.os.Bundle; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.support.v7.widget.LinearLayoutManager; | |
| import android.support.v7.widget.RecyclerView; | |
| import java.util.List; | |
| import butterknife.BindView; | |
| import butterknife.ButterKnife; | |
| import retrofit2.Call; | |
| import retrofit2.Callback; | |
| import retrofit2.Response; | |
| public class MainActivity extends AppCompatActivity { | |
| @BindView(R.id.rvListUser) | |
| RecyclerView rvListUser; | |
| private List<DataItem> listItem; | |
| private RecycleAdapter adapter; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| ButterKnife.bind(this); | |
| RestClient.getService().getList().enqueue(new Callback<ListUserResponse>() { | |
| @Override | |
| public void onResponse(Call<ListUserResponse> call, Response<ListUserResponse> response) { | |
| if (response.isSuccessful()){ | |
| listItem = response.body().getData(); | |
| adapter = new RecycleAdapter(listItem, MainActivity.this); | |
| rvListUser.setLayoutManager(new LinearLayoutManager(getApplicationContext())); | |
| rvListUser.setAdapter(adapter); | |
| } | |
| } | |
| @Override | |
| public void onFailure(Call<ListUserResponse> call, Throwable t) { | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment