SHARE
TWEET

MainActivity

a guest Jun 12th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package picodiploma.dicoding.myrecyclerview;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.support.v7.widget.LinearLayoutManager;
  6. import android.support.v7.widget.RecyclerView;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.LinearLayout;
  11.  
  12. import java.util.ArrayList;
  13.  
  14. public class MainActivity extends AppCompatActivity {
  15.  
  16.     private RecyclerView rvCategory;
  17.     private ArrayList<President> list = new ArrayList<>();
  18.  
  19.     @Override
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_main);
  23.  
  24.         rvCategory = findViewById(R.id.rv_category);
  25.         rvCategory.setHasFixedSize(true);
  26.  
  27.         list.addAll (PresidentData.getListData());
  28.         showRecyclerList();
  29.     }
  30.  
  31.     private void showRecyclerList() {
  32.         rvCategory.setLayoutManager(new LinearLayoutManager(this));
  33.         ListPresidentAdapter listPresidentAdapter = new ListPresidentAdapter(this);
  34.         listPresidentAdapter.setListPresident(list);
  35.         rvCategory.setAdapter(listPresidentAdapter);
  36.     }
  37.  
  38.     @Override
  39.     public boolean onCreateOptionsMenu(Menu menu){
  40.         getMenuInflater().inflate(R.menu.menu_main, menu);
  41.         return super.onCreateOptionsMenu(menu);
  42.     }
  43.  
  44.     @Override
  45.     public boolean onOptionsItemSelected(MenuItem item){
  46.         switch (item.getItemId()){
  47.             case R.id.action_list:
  48.                 break;
  49.  
  50.             case R.id.action_grid:
  51.                 break;
  52.  
  53.             case R.id.action_cardview:
  54.                 break;
  55.         }
  56.         return super.onOptionsItemSelected(item);
  57.     }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top