Guest User

Untitled

a guest
Apr 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. public class Adaptador extends RecyclerView.Adapter<Adaptador.CartaViewHolder> {
  2. private Context contexto;
  3. private List<Contenido> listacartas;
  4.  
  5. public Adaptador(Context contexto, List<Contenido> listacartas) {
  6. this.contexto = contexto;
  7. this.listacartas = listacartas;
  8. }
  9.  
  10. @Override
  11. public CartaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  12. LayoutInflater inflado = LayoutInflater.from(contexto);
  13. View vistosa = inflado.inflate(R.layout.cartas, null);
  14. return new CartaViewHolder(vistosa);
  15. }
  16.  
  17. @Override
  18. public void onBindViewHolder(CartaViewHolder holder, int position) {
  19.  
  20. Contenido datos = listacartas.get(position);
  21.  
  22. holder.nombre.setText(datos.getNombre());
  23. holder.imagen.setImageDrawable(contexto.getResources().getDrawable(datos.getImagen()));
  24. }
  25.  
  26. @Override
  27. public int getItemCount() {
  28. return listacartas.size();
  29. }
  30.  
  31. class CartaViewHolder extends RecyclerView.ViewHolder {
  32.  
  33. ImageView imagen;
  34. TextView nombre;
  35.  
  36. public CartaViewHolder(View itemView) {
  37. super(itemView);
  38.  
  39. imagen = itemView.findViewById(R.id.imageView);
  40. nombre = itemView.findViewById(R.id.textView);
  41. }
  42. }
  43.  
  44. @Override
  45. protected void onCreate(Bundle savedInstanceState) {
  46. super.onCreate(savedInstanceState);
  47. setContentView(R.layout.activity_main);
  48. click = findViewById(R.id.fragmento);
  49. numero = findViewById(R.id.numero);
  50.  
  51. blankFragment = new BlankFragment();
  52. findViewById(R.id.fragmento).setOnClickListener(new View.OnClickListener() {
  53. @Override
  54. public void onClick(View view) {
  55. getSupportFragmentManager().beginTransaction().add(R.id.contenedor, blankFragment).addToBackStack(null).commit();
  56. click.setVisibility(View.INVISIBLE);
  57. numero.setVisibility(View.INVISIBLE);
  58. }
  59. });
  60.  
  61.  
  62. }
  63.  
  64. @Override
  65. public void onBackPressed() {
  66. super.onBackPressed();
  67. click.setVisibility(View.VISIBLE);
  68. numero.setVisibility(View.VISIBLE);
  69. }
  70.  
  71. public class BlankFragment extends Fragment {
  72. RecyclerView reciclador;
  73. List<Contenido> listota;
  74. LinearLayoutManager layoutManager
  75. = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
  76.  
  77. public BlankFragment() {
  78. // Required empty public constructor
  79. }
  80.  
  81.  
  82. @Override
  83. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  84. Bundle savedInstanceState) {
  85. // Inflate the layout for this fragment
  86. View view = inflater.inflate(R.layout.fragment_blank, container, false);
  87. listota = new ArrayList<>();
  88.  
  89. reciclador = view.findViewById(R.id.Lista);
  90. reciclador.setLayoutManager(layoutManager);
  91. reciclador.setHasFixedSize(true);
  92. reciclador.setLayoutManager(new LinearLayoutManager(getContext()));
  93. listota.add(new Contenido(R.drawable.alacran, "Alacran"));
  94. listota.add(new Contenido(R.drawable.apache, "Apache"));
  95. listota.add(new Contenido(R.drawable.arana, "Araña"));
  96. listota.add(new Contenido(R.drawable.arbol, "Arbol"));
  97. listota.add(new Contenido(R.drawable.arpa, "Arpa"));
  98. listota.add(new Contenido(R.drawable.bandera, "Bandera"));
  99. listota.add(new Contenido(R.drawable.barril, "Barril"));
  100. listota.add(new Contenido(R.drawable.borracho, "Borracho"));
  101. listota.add(new Contenido(R.drawable.bota, "Bota"));
  102. listota.add(new Contenido(R.drawable.botella, "Botella"));
  103. listota.add(new Contenido(R.drawable.calavera, "Calavera"));
  104. listota.add(new Contenido(R.drawable.camaron, "Camaron"));
  105. listota.add(new Contenido(R.drawable.campana, "Campana"));
  106. listota.add(new Contenido(R.drawable.cantaro, "Catrin"));
  107. listota.add(new Contenido(R.drawable.cazo, "Cazo"));
  108. listota.add(new Contenido(R.drawable.chalupa, "Chalupa"));
  109. listota.add(new Contenido(R.drawable.corazon, "Corazon"));
  110. listota.add(new Contenido(R.drawable.corona, "Corona"));
  111. listota.add(new Contenido(R.drawable.cotorro, "Cotorro"));
  112. listota.add(new Contenido(R.drawable.dama, "Dama"));
  113. listota.add(new Contenido(R.drawable.diablito, "Diablito"));
  114. listota.add(new Contenido(R.drawable.escalera, "Escalera"));
  115. listota.add(new Contenido(R.drawable.estrella, "Estrella"));
  116. listota.add(new Contenido(R.drawable.gallo, "Gallo"));
  117. listota.add(new Contenido(R.drawable.garza, "Garza"));
  118. listota.add(new Contenido(R.drawable.gorrito, "Gorrito"));
  119. listota.add(new Contenido(R.drawable.jaras, "Jarras"));
  120. listota.add(new Contenido(R.drawable.luna, "Luna"));
  121. listota.add(new Contenido(R.drawable.maceta, "Maceta"));
  122. listota.add(new Contenido(R.drawable.mano, "Mano"));
  123. listota.add(new Contenido(R.drawable.melon, "Melon"));
  124. listota.add(new Contenido(R.drawable.muerte, "Muerte"));
  125. listota.add(new Contenido(R.drawable.mundo, "Mundo"));
  126. listota.add(new Contenido(R.drawable.musico, "Musico"));
  127. listota.add(new Contenido(R.drawable.negro, "Negro"));
  128. listota.add(new Contenido(R.drawable.nopal, "Nopal"));
  129. listota.add(new Contenido(R.drawable.pajaro, "Pajaro"));
  130. listota.add(new Contenido(R.drawable.palma, "Palma"));
  131. listota.add(new Contenido(R.drawable.paragauas, "Paraguas"));
  132. listota.add(new Contenido(R.drawable.pera, "Pera"));
  133. listota.add(new Contenido(R.drawable.pescado, "Pescado"));
  134. listota.add(new Contenido(R.drawable.pino, "Pino"));
  135. listota.add(new Contenido(R.drawable.rana, "Rana"));
  136. listota.add(new Contenido(R.drawable.rosa, "Rosa"));
  137. listota.add(new Contenido(R.drawable.sandolon, "Sandolon"));
  138. listota.add(new Contenido(R.drawable.sandria, "Sandia"));
  139. listota.add(new Contenido(R.drawable.sirena, "Sirena"));
  140. listota.add(new Contenido(R.drawable.sol, "Sol"));
  141. listota.add(new Contenido(R.drawable.soldado, "Soldado"));
  142. listota.add(new Contenido(R.drawable.tambor, "Tambor"));
  143. listota.add(new Contenido(R.drawable.valiente, "Valiente"));
  144. listota.add(new Contenido(R.drawable.venado, "Venado"));
  145. listota.add(new Contenido(R.drawable.violoncelo, "Violonchelo"));
  146.  
  147.  
  148.  
  149. Adaptador adapter = new Adaptador(getContext(), listota);
  150.  
  151. reciclador.setAdapter(adapter);
  152.  
  153. return view;
  154. }
Add Comment
Please, Sign In to add comment