Escolar Documentos
Profissional Documentos
Cultura Documentos
Manejo de
RecyclerView II
dheeyi@gmail.com
Objetivo
Se tiene como objetivo mostrar un listado de items (elementos) utilizando el componente RECYCLERVIEW de android. Este elemento
nos permite mostrar listas con una excelente presentación al usuario.
Además es posible agregar colecciones desde la aplicación de manera local y también acceder y listar elementos que se encuentren
en INTERNET. Es decir es posible listar ítems que se encuentren localmente y otros que estén disponibles en Internet.
Ver el vídeo de lanzamiento
logotipo usado
<color name="colorPrimaryDark">#FB8620</color>
b. Debe tener la siguiente apariencia
5. Modificar el MainActivity.java (El activity que usa el xml modificado anteriormente).
btPlay.setOnClickListener(this);
btPause.setOnClickListener(this);
btStop.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btPlay: _clickPlay(); break;
case R.id.btPause: _clickPause(); break;
case R.id.btStop: _clickStop(); break;
}
}
6. Hasta este punto siguiendo los pasos anteriores solo queda hacer correr la aplicación. El comportamiento esperado debería
ser los siguientes:
a. Al presionar el button PLAY la canción empieza a sonar.
b. Al presionar el button PAUSE la canción se detiene.
c. Finalmente el button STOP termina la canción.
7. Iniciar la aplicación.
a. remove private.
Nombre Completo
2 oel Arancibia
3 Raquel
4 Sandra - Julian
5 Jomar - Gabriela
6 Einar - Bernarda
7 Oscar I
9. Modificar el archivo .xml para que tenga la siguiente apariencia.
Nombre Completo
1 Jomar - Gabriela
2 Joel Arancibia
Nombre Completo
1 Jose Luis - Erick
2 Esteban Pereira
3 Oscar I.
10. Agregar la funcionalidad de reproducir los archivos .mp3 en el recycler view. (Este ejercicio tiene un valor de 15 %)
a.
3 Esteban Pereira
7
public class RecorderAdapter {
MediaPlayer player;
Context context;
Integer sound;
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*"
>
<TableRow>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civItem"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:id="@+id/tvImage"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="@string/bolivia"
android:layout_toRightOf="@id/civItem"
android:layout_centerVertical="true"
android:padding="8dp"
android:textColor="@color/colorText"
android:textSize="16sp"
/>
<Button
android:id="@+id/btPlay1"
android:layout_width="60dp"
android:layout_height="match_parent"
android:text="@string/play"
/>
<Button
android:id="@+id/btPause1"
android:layout_width="60dp"
android:layout_height="match_parent"
android:text="@string/pause"
/>
<Button
android:id="@+id/btStop1"
android:layout_width="60dp"
android:layout_height="match_parent"
android:text="@string/stop"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
package com.dheeyi.recyclerview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import java.util.ArrayList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_initImageBitmaps();
_initRecyclerView();
}
imageUrls.add(R.drawable.sp);
names.add("Spotify");
sounds.add(R.raw.helloworld);
imageUrls.add(R.drawable.fb);
names.add("Facebook");
sounds.add(R.raw.bensoundsunny);
imageUrls.add(R.drawable.dl);
names.add("Duolingo");
sounds.add(R.raw.helloworld);
imageUrls.add(R.drawable.mg);
names.add("Messenger");
sounds.add(R.raw.bensoundsunny);
imageUrls.add(R.drawable.sc);
names.add("Snapchat");
sounds.add(R.raw.helloworld);
imageUrls.add(R.drawable.tw);
names.add("Twitter");
sounds.add(R.raw.bensoundsunny);
RVADAPTER
package com.dheeyi.recyclerview;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
//accedemos al resource file RL_LIST_ITEM
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.rl_list_item, viewGroup, false);
//utilizamos la clase ViewHolder
ViewHolder vHolder = new ViewHolder(view);
return vHolder;
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
Log.d(TAG,"onBindViewHolde... called!!!");
//para el loading de las imagenes
Glide.with(context)
.asBitmap()
.load(images.get(position))
.into(viewHolder.circleImage);
//seateamos el texto
viewHolder.tvTextImageName.setText(imageNames.get(position));
viewHolder.btPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recorderAdapter = new RecorderAdapter(context, sounds.get(position));
recorderAdapter._clickPlay();
}
});
viewHolder.btPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recorderAdapter = new RecorderAdapter(context, sounds.get(position));
recorderAdapter._clickPause();
}
});
viewHolder.btStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recorderAdapter = new RecorderAdapter(context, sounds.get(position));
recorderAdapter._clickStop();
}
});
//toast al presionar sobre el texto
viewHolder.rlContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "Clicked on: " + imageNames.get(position));
message(imageNames.get(position));
}
});
}
@Override
public int getItemCount() {
return imageNames.size();
}
11. Cuando se presiona PLAY y se presiona nuevamente PLAY en otra canción. El audio debe detenerse (STOP) para que se
pueda ejecutar la canción actual.
a.
Nombre Completo
2
3
4
b.
12. Deshabilitar el botón PAUSE cuando se presiona PLAY.
a.
Nombre Completo
Nombre Completo
4
b.
Nombre Completo