Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Adaptador extends RecyclerView.Adapter<Adaptador.CartaViewHolder> {
- private Context contexto;
- private List<Contenido> listacartas;
- public Adaptador(Context contexto, List<Contenido> listacartas) {
- this.contexto = contexto;
- this.listacartas = listacartas;
- }
- @Override
- public CartaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- LayoutInflater inflado = LayoutInflater.from(contexto);
- View vistosa = inflado.inflate(R.layout.cartas, null);
- return new CartaViewHolder(vistosa);
- }
- @Override
- public void onBindViewHolder(CartaViewHolder holder, int position) {
- Contenido datos = listacartas.get(position);
- holder.nombre.setText(datos.getNombre());
- holder.imagen.setImageDrawable(contexto.getResources().getDrawable(datos.getImagen()));
- }
- @Override
- public int getItemCount() {
- return listacartas.size();
- }
- class CartaViewHolder extends RecyclerView.ViewHolder {
- ImageView imagen;
- TextView nombre;
- public CartaViewHolder(View itemView) {
- super(itemView);
- imagen = itemView.findViewById(R.id.imageView);
- nombre = itemView.findViewById(R.id.textView);
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- click = findViewById(R.id.fragmento);
- numero = findViewById(R.id.numero);
- blankFragment = new BlankFragment();
- findViewById(R.id.fragmento).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- getSupportFragmentManager().beginTransaction().add(R.id.contenedor, blankFragment).addToBackStack(null).commit();
- click.setVisibility(View.INVISIBLE);
- numero.setVisibility(View.INVISIBLE);
- }
- });
- }
- @Override
- public void onBackPressed() {
- super.onBackPressed();
- click.setVisibility(View.VISIBLE);
- numero.setVisibility(View.VISIBLE);
- }
- public class BlankFragment extends Fragment {
- RecyclerView reciclador;
- List<Contenido> listota;
- LinearLayoutManager layoutManager
- = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
- public BlankFragment() {
- // Required empty public constructor
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View view = inflater.inflate(R.layout.fragment_blank, container, false);
- listota = new ArrayList<>();
- reciclador = view.findViewById(R.id.Lista);
- reciclador.setLayoutManager(layoutManager);
- reciclador.setHasFixedSize(true);
- reciclador.setLayoutManager(new LinearLayoutManager(getContext()));
- listota.add(new Contenido(R.drawable.alacran, "Alacran"));
- listota.add(new Contenido(R.drawable.apache, "Apache"));
- listota.add(new Contenido(R.drawable.arana, "Araña"));
- listota.add(new Contenido(R.drawable.arbol, "Arbol"));
- listota.add(new Contenido(R.drawable.arpa, "Arpa"));
- listota.add(new Contenido(R.drawable.bandera, "Bandera"));
- listota.add(new Contenido(R.drawable.barril, "Barril"));
- listota.add(new Contenido(R.drawable.borracho, "Borracho"));
- listota.add(new Contenido(R.drawable.bota, "Bota"));
- listota.add(new Contenido(R.drawable.botella, "Botella"));
- listota.add(new Contenido(R.drawable.calavera, "Calavera"));
- listota.add(new Contenido(R.drawable.camaron, "Camaron"));
- listota.add(new Contenido(R.drawable.campana, "Campana"));
- listota.add(new Contenido(R.drawable.cantaro, "Catrin"));
- listota.add(new Contenido(R.drawable.cazo, "Cazo"));
- listota.add(new Contenido(R.drawable.chalupa, "Chalupa"));
- listota.add(new Contenido(R.drawable.corazon, "Corazon"));
- listota.add(new Contenido(R.drawable.corona, "Corona"));
- listota.add(new Contenido(R.drawable.cotorro, "Cotorro"));
- listota.add(new Contenido(R.drawable.dama, "Dama"));
- listota.add(new Contenido(R.drawable.diablito, "Diablito"));
- listota.add(new Contenido(R.drawable.escalera, "Escalera"));
- listota.add(new Contenido(R.drawable.estrella, "Estrella"));
- listota.add(new Contenido(R.drawable.gallo, "Gallo"));
- listota.add(new Contenido(R.drawable.garza, "Garza"));
- listota.add(new Contenido(R.drawable.gorrito, "Gorrito"));
- listota.add(new Contenido(R.drawable.jaras, "Jarras"));
- listota.add(new Contenido(R.drawable.luna, "Luna"));
- listota.add(new Contenido(R.drawable.maceta, "Maceta"));
- listota.add(new Contenido(R.drawable.mano, "Mano"));
- listota.add(new Contenido(R.drawable.melon, "Melon"));
- listota.add(new Contenido(R.drawable.muerte, "Muerte"));
- listota.add(new Contenido(R.drawable.mundo, "Mundo"));
- listota.add(new Contenido(R.drawable.musico, "Musico"));
- listota.add(new Contenido(R.drawable.negro, "Negro"));
- listota.add(new Contenido(R.drawable.nopal, "Nopal"));
- listota.add(new Contenido(R.drawable.pajaro, "Pajaro"));
- listota.add(new Contenido(R.drawable.palma, "Palma"));
- listota.add(new Contenido(R.drawable.paragauas, "Paraguas"));
- listota.add(new Contenido(R.drawable.pera, "Pera"));
- listota.add(new Contenido(R.drawable.pescado, "Pescado"));
- listota.add(new Contenido(R.drawable.pino, "Pino"));
- listota.add(new Contenido(R.drawable.rana, "Rana"));
- listota.add(new Contenido(R.drawable.rosa, "Rosa"));
- listota.add(new Contenido(R.drawable.sandolon, "Sandolon"));
- listota.add(new Contenido(R.drawable.sandria, "Sandia"));
- listota.add(new Contenido(R.drawable.sirena, "Sirena"));
- listota.add(new Contenido(R.drawable.sol, "Sol"));
- listota.add(new Contenido(R.drawable.soldado, "Soldado"));
- listota.add(new Contenido(R.drawable.tambor, "Tambor"));
- listota.add(new Contenido(R.drawable.valiente, "Valiente"));
- listota.add(new Contenido(R.drawable.venado, "Venado"));
- listota.add(new Contenido(R.drawable.violoncelo, "Violonchelo"));
- Adaptador adapter = new Adaptador(getContext(), listota);
- reciclador.setAdapter(adapter);
- return view;
- }
Add Comment
Please, Sign In to add comment