Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.alumnociclo.registrojugadores;
- import android.graphics.Movie;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- import java.util.ArrayList;
- import java.util.List;
- public class MainActivity extends AppCompatActivity {
- private ListView lv;
- private jugadorAdapter jAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- lv = (ListView) findViewById(R.id.listview1);
- ArrayList<jugadores> jugadoresList = new ArrayList<>();
- jugadoresList.add(new jugadores(R.drawable.benzema, "Karim Benzema" , "Real Madrid"));
- jugadoresList.add(new jugadores(R.drawable.ramos, "Sergio Ramos" , "Real Madrid"));
- jugadoresList.add(new jugadores(R.drawable.mbappe, "Kylian Mbappe" , "PSG"));
- jAdapter = new jugadorAdapter(this,R.layout.lista_elementos,jugadoresList);
- //jAdapter = new jugadorAdapter(this,jugadoresList);
- lv.setAdapter(jAdapter);
- }
- }
- -----------------------------------------------------------------------
- package com.example.alumnociclo.registrojugadores;
- public class jugadores {
- // Store the id of the player
- private int jImageDrawable;
- // Store the name of the player
- private String jName;
- // Store the player team
- private String jTeam;
- // Constructor that is used to create an instance of the player object
- public jugadores(int jImageDrawable, String jName, String jRelease) {
- this.jImageDrawable = jImageDrawable;
- this.jName = jName;
- this.jTeam = jRelease;
- }
- public int getmImageDrawable() {
- return jImageDrawable;
- }
- public void setmImageDrawable(int mImageDrawable) {
- this.jImageDrawable = mImageDrawable;
- }
- public String getjName() {
- return jName;
- }
- public void setjName(String mName) {
- this.jName = mName;
- }
- public String getjTeam() {
- return jTeam;
- }
- public void setjTeam(String mRelease) {
- this.jTeam = mRelease;
- }
- }
- -----------------------------------------------------------------------------------
- package com.example.alumnociclo.registrojugadores;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.support.annotation.LayoutRes;
- import android.support.annotation.NonNull;
- import android.support.annotation.Nullable;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import java.util.ArrayList;
- import java.util.List;
- public class jugadorAdapter extends ArrayAdapter<jugadores> {
- private Context mContext;
- private List<jugadores> jugadoresList = new ArrayList<>();
- public jugadorAdapter(Context context,
- int resource,ArrayList<jugadores> list) {
- super(context, 0, list);
- mContext = context;
- jugadoresList = list;
- }
- @NonNull
- @Override
- public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
- View listItem = convertView;
- if (listItem == null)
- listItem = LayoutInflater.from(mContext).inflate(R.layout.lista_elementos, parent, false);
- jugadores jugador = jugadoresList.get(position);
- ImageView image = (ImageView) listItem.findViewById(R.id.imageView_poster);
- image.setImageResource(jugador.getmImageDrawable());
- TextView name = (TextView) listItem.findViewById(R.id.textView_name);
- name.setText(jugador.getjName());
- TextView release = (TextView) listItem.findViewById(R.id.textView_team);
- release.setText(jugador.getjTeam());
- return listItem;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement