Advertisement
Geeo

Usted ya ve

Jan 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. package com.example.alumnociclo.registrojugadores;
  2.  
  3. import android.graphics.Movie;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.ListView;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13. private ListView lv;
  14. private jugadorAdapter jAdapter;
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19.  
  20. lv = (ListView) findViewById(R.id.listview1);
  21. ArrayList<jugadores> jugadoresList = new ArrayList<>();
  22. jugadoresList.add(new jugadores(R.drawable.benzema, "Karim Benzema" , "Real Madrid"));
  23. jugadoresList.add(new jugadores(R.drawable.ramos, "Sergio Ramos" , "Real Madrid"));
  24. jugadoresList.add(new jugadores(R.drawable.mbappe, "Kylian Mbappe" , "PSG"));
  25.  
  26.  
  27. jAdapter = new jugadorAdapter(this,R.layout.lista_elementos,jugadoresList);
  28. //jAdapter = new jugadorAdapter(this,jugadoresList);
  29. lv.setAdapter(jAdapter);
  30.  
  31. }
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. -----------------------------------------------------------------------
  43.  
  44. package com.example.alumnociclo.registrojugadores;
  45.  
  46. public class jugadores {
  47.  
  48. // Store the id of the player
  49. private int jImageDrawable;
  50. // Store the name of the player
  51. private String jName;
  52. // Store the player team
  53. private String jTeam;
  54.  
  55.  
  56. // Constructor that is used to create an instance of the player object
  57. public jugadores(int jImageDrawable, String jName, String jRelease) {
  58.  
  59. this.jImageDrawable = jImageDrawable;
  60. this.jName = jName;
  61. this.jTeam = jRelease;
  62. }
  63.  
  64. public int getmImageDrawable() {
  65. return jImageDrawable;
  66. }
  67.  
  68. public void setmImageDrawable(int mImageDrawable) {
  69. this.jImageDrawable = mImageDrawable;
  70. }
  71.  
  72. public String getjName() {
  73. return jName;
  74. }
  75.  
  76. public void setjName(String mName) {
  77. this.jName = mName;
  78. }
  79.  
  80. public String getjTeam() {
  81. return jTeam;
  82. }
  83.  
  84. public void setjTeam(String mRelease) {
  85. this.jTeam = mRelease;
  86. }
  87. }
  88. -----------------------------------------------------------------------------------
  89.  
  90. package com.example.alumnociclo.registrojugadores;
  91.  
  92. import android.annotation.SuppressLint;
  93. import android.content.Context;
  94. import android.support.annotation.LayoutRes;
  95. import android.support.annotation.NonNull;
  96. import android.support.annotation.Nullable;
  97. import android.view.LayoutInflater;
  98. import android.view.View;
  99. import android.view.ViewGroup;
  100. import android.widget.ArrayAdapter;
  101. import android.widget.ImageView;
  102. import android.widget.TextView;
  103. import java.util.ArrayList;
  104. import java.util.List;
  105.  
  106.  
  107. public class jugadorAdapter extends ArrayAdapter<jugadores> {
  108.  
  109. private Context mContext;
  110. private List<jugadores> jugadoresList = new ArrayList<>();
  111.  
  112.  
  113. public jugadorAdapter(Context context,
  114. int resource,ArrayList<jugadores> list) {
  115. super(context, 0, list);
  116. mContext = context;
  117. jugadoresList = list;
  118. }
  119.  
  120. @NonNull
  121. @Override
  122. public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  123. View listItem = convertView;
  124. if (listItem == null)
  125. listItem = LayoutInflater.from(mContext).inflate(R.layout.lista_elementos, parent, false);
  126.  
  127. jugadores jugador = jugadoresList.get(position);
  128.  
  129. ImageView image = (ImageView) listItem.findViewById(R.id.imageView_poster);
  130. image.setImageResource(jugador.getmImageDrawable());
  131.  
  132. TextView name = (TextView) listItem.findViewById(R.id.textView_name);
  133. name.setText(jugador.getjName());
  134.  
  135. TextView release = (TextView) listItem.findViewById(R.id.textView_team);
  136. release.setText(jugador.getjTeam());
  137.  
  138. return listItem;
  139. }
  140.  
  141.  
  142.  
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement