Created
August 31, 2018 21:59
-
-
Save JeovaniMartinez/f83469211e59a20207eac452712836bc to your computer and use it in GitHub Desktop.
Tutorial Android - Crear ListView Personalizado
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.tutorialesje.lista.DetallesPelicula"> | |
<TextView | |
android:id="@+id/tbTituloDescripcion" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginLeft="8dp" | |
android:layout_marginRight="8dp" | |
android:layout_marginTop="8dp" | |
android:text="TextView" | |
android:textSize="18sp" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<TextView | |
android:id="@+id/tvdescripcion" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginLeft="8dp" | |
android:layout_marginTop="8dp" | |
android:text="TextView" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/tbTituloDescripcion" /> | |
</android.support.constraint.ConstraintLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.tutorialesje.lista.Principal"> | |
<ListView | |
android:id="@+id/lvLista" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginRight="8dp" | |
android:layout_marginTop="8dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
</android.support.constraint.ConstraintLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.tutorialesje.lista.VisorImagen"> | |
<ImageView | |
android:id="@+id/ivImagenCompleta" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginRight="16dp" | |
android:layout_marginTop="8dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:srcCompat="@drawable/exmachina" /> | |
</android.support.constraint.ConstraintLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tutorialesje.lista; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
import android.widget.ImageView; | |
import android.widget.RatingBar; | |
import android.widget.TextView; | |
/** | |
* Created by Jeovani on 27/10/2017. | |
*/ | |
public class Adaptador extends BaseAdapter { | |
private static LayoutInflater inflater = null; | |
Context contexto; | |
String[][] datos; | |
int[] datosImg; | |
public Adaptador(Context conexto, String[][] datos, int[] imagenes) | |
{ | |
this.contexto = conexto; | |
this.datos = datos; | |
this.datosImg = imagenes; | |
inflater = (LayoutInflater)conexto.getSystemService(conexto.LAYOUT_INFLATER_SERVICE); | |
} | |
@Override | |
public View getView(int i, View convertView, ViewGroup parent) { | |
final View vista = inflater.inflate(R.layout.elemento_lista, null); | |
TextView titulo = (TextView) vista.findViewById(R.id.tvTitulo); | |
TextView duracion = (TextView) vista.findViewById(R.id.tvDuracion); | |
TextView director = (TextView) vista.findViewById(R.id.tvDirector); | |
ImageView imagen = (ImageView) vista.findViewById(R.id.ivImagen); | |
RatingBar calificacion = (RatingBar) vista.findViewById(R.id.ratingBarPel); | |
titulo.setText(datos[i][0]); | |
director.setText(datos[i][1]); | |
duracion.setText("Duración " + datos[i][2]); | |
imagen.setImageResource(datosImg[i]); | |
calificacion.setProgress(Integer.valueOf(datos[i][3])); | |
imagen.setTag(i); | |
imagen.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent visorImagen = new Intent(contexto, VisorImagen.class); | |
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]); | |
contexto.startActivity(visorImagen); | |
} | |
}); | |
return vista; | |
} | |
@Override | |
public int getCount() { | |
return datosImg.length; | |
} | |
@Override | |
public Object getItem(int position) { | |
return null; | |
} | |
@Override | |
public long getItemId(int position) { | |
return 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tutorialesje.lista; | |
import android.content.Intent; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.TextView; | |
public class DetallesPelicula extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_detalles_pelicula); | |
TextView titulo = (TextView) findViewById(R.id.tbTituloDescripcion); | |
TextView detalles = (TextView) findViewById(R.id.tvdescripcion); | |
Intent intent = getIntent(); | |
Bundle b = intent.getExtras(); | |
if(b!=null) { | |
titulo.setText(b.getString("TIT")); | |
detalles.setText(b.getString("DET")); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" android:layout_height="match_parent"> | |
<android.support.constraint.Guideline | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/guideline" | |
app:layout_constraintGuide_begin="44dp" | |
android:orientation="horizontal" /> | |
<android.support.constraint.Guideline | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/guideline2" | |
app:layout_constraintGuide_begin="84dp" | |
android:orientation="horizontal" /> | |
<android.support.constraint.Guideline | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/guideline3" | |
app:layout_constraintGuide_begin="118dp" | |
android:orientation="horizontal" /> | |
<android.support.constraint.Guideline | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/guideline4" | |
app:layout_constraintGuide_begin="172dp" | |
android:orientation="horizontal" /> | |
<android.support.constraint.Guideline | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/guideline5" | |
app:layout_constraintGuide_begin="193dp" | |
android:orientation="horizontal" /> | |
<android.support.constraint.Guideline | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/guideline6" | |
app:layout_constraintGuide_begin="16dp" | |
android:orientation="horizontal" /> | |
<android.support.constraint.Guideline | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/guideline7" | |
app:layout_constraintGuide_begin="122dp" | |
android:orientation="vertical" /> | |
<TextView | |
android:id="@+id/tvTitulo" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginTop="8dp" | |
android:text="TextView" | |
android:textSize="18sp" | |
app:layout_constraintBottom_toTopOf="@+id/guideline2" | |
app:layout_constraintLeft_toLeftOf="@+id/guideline7" | |
app:layout_constraintTop_toTopOf="@+id/guideline" /> | |
<TextView | |
android:id="@+id/tvDirector" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginTop="8dp" | |
android:text="TextView" | |
android:textSize="16sp" | |
app:layout_constraintBottom_toTopOf="@+id/guideline3" | |
app:layout_constraintLeft_toLeftOf="@+id/guideline7" | |
app:layout_constraintTop_toTopOf="@+id/guideline2" /> | |
<TextView | |
android:id="@+id/tvDuracion" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginRight="8dp" | |
android:text="TextView" | |
app:layout_constraintBottom_toTopOf="@+id/guideline4" | |
app:layout_constraintRight_toRightOf="parent" /> | |
<RatingBar | |
android:id="@+id/ratingBarPel" | |
style="@style/Widget.AppCompat.RatingBar.Indicator" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginTop="8dp" | |
app:layout_constraintBottom_toTopOf="@+id/guideline4" | |
app:layout_constraintLeft_toLeftOf="@+id/guideline7" | |
app:layout_constraintTop_toTopOf="@+id/guideline3" /> | |
<ImageView | |
android:id="@+id/ivImagen" | |
android:layout_width="105dp" | |
android:layout_height="138dp" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginRight="8dp" | |
android:layout_marginTop="8dp" | |
app:layout_constraintBottom_toTopOf="@+id/guideline5" | |
app:layout_constraintHorizontal_bias="1.0" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toLeftOf="@+id/guideline7" | |
app:layout_constraintTop_toTopOf="@+id/guideline6" | |
app:srcCompat="@drawable/exmachina" /> | |
</android.support.constraint.ConstraintLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tutorialesje.lista; | |
import android.content.Intent; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.AdapterView; | |
import android.widget.ListView; | |
public class Principal extends AppCompatActivity { | |
ListView lista; | |
String[][] datos = { | |
{"Interestelar", "Christopher Nolan", "2:49", "9", "Interstellar (Interestelar en Hispanoamérica) es una película épica de ciencia ficción estadounidense de 2014, dirigida por Christopher Nolan y protagonizada por Matthew McConaughey, Anne Hathaway, Jessica Chastain, Michael Caine y Matt Damon. La película presenta a un equipo de astronautas que viaja a través de un agujero de gusano en busca de un nuevo hogar para la humanidad. Los hermanos Christopher y Jonathan Nolan escribieron el guion, que tuvo su origen en un borrador que Jonathan desarrolló en 2007. Christopher Nolan produjo la película junto a su esposa Emma Thomas mediante su compañía productora Syncopy, y con Lynda Obst a través de Lynda Obst Productions. El físico teórico Kip Thorne, cuyo trabajo inspiró la película, fue productor ejecutivo y participó como consultor científico. Warner Bros., Paramount Pictures y Legendary Pictures cofinanciaron la película."}, | |
{"Logan", "James Mangold", "2:17", "7", "Logan(Logan: Wolverine en Hispanoamérica) es una película estadounidense de 2017 y la última de la trilogía de Wolverine, basada en el personaje de Wolverine, de Marvel Comics, y producida por la 20th Century Fox. Se estrenó el 3 de marzo de 2017, protagonizada por Hugh Jackman y Patrick Stewart siendo esta sus últimas apariciones como Wolverine y el Profesor X en la franquicia de X-Men."}, | |
{"Everest", "Baltasar Kormákur", "2:01", "8", "Everest es una película estadounidense estrenada el 18 de septiembre de 2015, dirigida por Baltasar Kormákur y escrita por Justin Isbell y William Nicholson. La cinta, que tiene como protagonistas a Jason Clarke, Josh Brolin, John Hawkes, Robin Wright, Michael Kelly, Keira Knightley, Emily Watson, Sam Worthington y Jake Gyllenhaal, narra la tragedia ocurrida en el monte Everest el 10 de mayo de 1996, en la que ocho alpinistas fallecieron debido a una tormenta."}, | |
{"Titanes del Pacífico", "Guillermo del Toro", "2:12", "7", "Pacific Rim (Titanes del Pacífico en Hispanoamérica) es una película estadounidense de ciencia ficción del 2013 dirigida por Guillermo del Toro, escrita por Del Toro y Travis Beacham, y protagonizada por Charlie Hunnam, Idris Elba, Rinko Kikuchi, Charlie Day, Robert Kazinsky, Max Martini, y Ron Perlman. La película está ambientada en la década de 2020, cuando la Tierra es atacada por kaijus, monstruos colosales que han surgido a partir de un portal interdimensional en el fondo del Océano Pacífico, llamado \"El Abismo\". Para luchar contra los monstruos, la humanidad se une para crear a los Jaegers: gigantescas máquinas humanoides, cada una controlada por dos pilotos cuyas mentes están unidas por un puente neural (similares a los personajes llamados Headmasters de Transformers o a las unidades EVA (mecha) de Neon Genesis Evangelion). Centrándose en los días posteriores de la guerra, la historia sigue a Raleigh Becket, un piloto jaeger llamado de su retiro, que se asociará con la piloto novata Mako Mori en un último esfuerzo para derrotar a los kaijus."}, | |
{"Ex Machina", "Alex Garland", "1:48", "9", "Ex Machina es una película de ciencia ficción británica de 2015, escrita y dirigida por Alex Garland, siendo su primera película como director. Está protagonizada por Domhnall Gleeson, Alicia Vikander, Oscar Isaac y Sonoya Mizuno. Ex Machina cuenta la historia de Caleb, un programador de la empresa Bluebook, quien es invitado por Nathan, el Presidente de la compañía para la cual él trabaja, con el fin de realizar la prueba de Turing a un androide con inteligencia artificial. La película ha recibido principalmente críticas positivas de los expertos. La cinta ganó el Óscar a los mejores efectos visuales."}, | |
{"Arrival (La llegada)", "Denis Villeneuve", "1:56", "8", "Arrival (titulada en español como La llegada) es una película estadounidense de drama y ciencia ficción, dirigida por Denis Villeneuve y escrita por Eric Heisserer. Con Amy Adams y Jeremy Renner en los papeles principales, está basada en el premiado relato La historia de tu vida (Story of Your Life) de Ted Chiang. Fue estrenada mundialmente el 1 de septiembre de 2016 en el Festival Internacional de Cine de Venecia."} | |
}; | |
int[] datosImg = {R.drawable.interestelar, R.drawable.logan, R.drawable.everest, R.drawable.titanes, R.drawable.exmachina, R.drawable.arrival}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_principal); | |
lista = (ListView) findViewById(R.id.lvLista); | |
lista.setAdapter(new Adaptador(this, datos, datosImg)); | |
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
Intent visorDetalles = new Intent(view.getContext(), DetallesPelicula.class); | |
visorDetalles.putExtra("TIT", datos[position][0]); | |
visorDetalles.putExtra("DET", datos[position][4]); | |
startActivity(visorDetalles); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tutorialesje.lista; | |
import android.content.Intent; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.ImageView; | |
public class VisorImagen extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_visor_imagen); | |
ImageView img = (ImageView) findViewById(R.id.ivImagenCompleta); | |
Intent intent = getIntent(); | |
Bundle b = intent.getExtras(); | |
if(b!=null) { | |
img.setImageResource(b.getInt("IMG")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Disculpa como puedo poner en la ventana donde aparece la descripción un botón para que me dirija a un enlace de YouTube por ejemplo que sea el tráiler de la pelicular .