adenhidayat

MeinMenu

Mar 11th, 2018
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.79 KB | None | 0 0
  1. package com.adek.tutorandroid;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.support.v7.widget.GridLayoutManager;
  6. import android.support.v7.widget.RecyclerView;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.     RecyclerView recyclerView;
  13.     RecyclerView.LayoutManager layoutManager;
  14.     AdapterMainMenu adapterMainMenu;
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.         recyclerView= findViewById(R.id.tampilanmainmenu);
  20.         layoutManager = new GridLayoutManager(getApplicationContext(),3);
  21.         layoutManager.setAutoMeasureEnabled(true);
  22.         recyclerView.setHasFixedSize(false);
  23.         recyclerView.setLayoutManager(layoutManager);
  24.  
  25.         adapterMainMenu = new AdapterMainMenu(getApplicationContext(),getData());
  26.         recyclerView.setAdapter(adapterMainMenu);
  27.  
  28.     }
  29.  
  30.     private List<ModelMainMenu> getData(){
  31.         List<ModelMainMenu> data = new ArrayList<>();
  32.         data.add(new ModelMainMenu("Facebook",R.drawable.ic_facebook));
  33.         data.add(new ModelMainMenu("Twitter",R.drawable.ic_twitter));
  34.         data.add(new ModelMainMenu("Whatsapp",R.drawable.ic_whatsapp));
  35.         data.add(new ModelMainMenu("Google+",R.drawable.ic_google_plus));
  36.         data.add(new ModelMainMenu("Linkedin",R.drawable.ic_linkedin));
  37.         data.add(new ModelMainMenu("Youtube",R.drawable.ic_youtube));
  38.         data.add(new ModelMainMenu("Snapchat",R.drawable.ic_snapchat));
  39.         data.add(new ModelMainMenu("Pinterest",R.drawable.ic_pinterest));
  40.         data.add(new ModelMainMenu("Twitch",R.drawable.ic_twitch));
  41.  
  42.  
  43.  
  44.         return data;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment