-
Notifications
You must be signed in to change notification settings - Fork 0
Cuestionario
vjgonzalez edited this page May 11, 2019
·
2 revisions
El módulo cuestionario permite definir y presentar preguntas con formato multiple choice.
La clases principales son AdministradorCuestionario y CuestionarioBaseActivity:
Un cuestionario se define mediante un archivo XML y puede mostrarse tanto en un layout por defecto como en un layout custom.
Funcionalidades incluidas en el módulo:
- Soporte para animaciones ante respuestas correctas e incorrectas.
- Asignación opcional de puntajes para distintas preguntas.
- Soporte para preguntas con más de una respuesta correcta
- Layouts por defecto y soporte para layouts customizados
El XML que define el cuestionario es validado contra el schema cuestionario.xsd
, incluido en el módulo.
<?xml version="1.0"?>
<cuestionario
xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.w3schools.com cuestionario.xsd">
<pregunta texto="¿DE QUÉ COLOR ES EL CIELO?">
<respuestaCorrecta texto="CELESTE"/>
<respuestaInCorrecta texto="ROJO"/>
<respuestaInCorrecta texto="AMARILLO"/>
<respuestaInCorrecta texto="VERDE"/>
<respuestaInCorrecta texto="BLANCO"/>
</pregunta>
<pregunta texto="¿QUÉ ROPA VA EN LOS PIES?">
<respuestaCorrecta texto="ZAPATILLAS" />
<respuestaCorrecta texto="MEDIAS" />
<respuestaInCorrecta texto="REMERA" />
<respuestaInCorrecta texto="CAMPERA" />
<respuestaInCorrecta texto="GUANTES" />
<respuestaInCorrecta texto="PANTALÓN" />
</pregunta>
<pregunta texto="¿DÓNDE USARÍAS UNA CAMISA FORMAL?">
<respuestaCorrecta texto="EN UN CASAMIENTO" />
<respuestaInCorrecta texto="EN LA PLAYA" />
<respuestaInCorrecta texto="JUGANDO EN LA PLAZA" />
<respuestaInCorrecta texto="HACIENDO DEPORTE" />
<respuestaInCorrecta texto="DURMIENDO EN LA CAMA" />
</pregunta>
</cuestionario>
La clase CuestionarioBaseActivity tiene un comportamiento básico, con animaciones por defecto y llamada a finish() al completar el cuestionario. Se recomienda extender esta clase y sobreescribir los siguientes métodos:
-
MostrarFeedbackOpcionCorrecta: Llamar a
onComplete.ejecutar()
al finalizar la animación de feedback. -
MostrarFeedbackOpcionIncorrecta: Llamar a
onComplete.ejecutar()
al finalizar la animación de feedback. -
CuestionarioCompleto: Avanzar a la Activity siguiente al finalizar la animación de feedback. Si no se sobreescribe este método, la implementación base llama a
finish()
.
Importante: No llamar a la implementación de CuestionarioBaseActivity al sobreescribir estos métodos.
Ejemplo:
public class CuestionarioCustomActivity extends CuestionarioBaseActivity {
@Override
protected void MostrarFeedbackOpcionCorrecta(View opcionElegidaView, final Ejecutable onComplete)
{
Toast toast = Toast.makeText(this, "CUSTOM FEEDBACK OPCION CORRECTA", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
// Para continuar con un delay y darle tiempo a la animación
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if(onComplete != null)
{
onComplete.ejecutar();
}
}
}, 3000);
}
@Override
protected void MostrarFeedbackOpcionIncorrecta(View opcionElegidaView, final Ejecutable onComplete)
{
Toast toast = Toast.makeText(this, "CUSTOM FEEDBACK OPCION INCORRECTA", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
// Para continuar con un delay y darle tiempo a la animación
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if(onComplete != null)
{
onComplete.ejecutar();
}
}
}, 3000);
}
@Override
protected void CuestionarioCompleto(View opcionElegidaView)
{
Log.d("DANE","CUESTIONARIO COMPLETO");
Toast toast = Toast.makeText(this, "CUSTOM FEEDBACK CUESTIONARIO COMPLETO", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
// Para continuar con un delay y darle tiempo a la animación
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
finish();
}
}, 3000);
}
}
int cantidadDePreguntasAMostrar = 2;
// Opción 1: Layouts por defecto
Intent intent = AdministradorCuestionario.obtenerIntent(getApplicationContext(), R.xml.cuestionario_test, CuestionarioBaseActivity.class, cantidadDePreguntasAMostrar );
startActivity(intent);
// Opción 2: Layouts custom
Intent intent = AdministradorCuestionario.obtenerIntent(getApplicationContext(), R.xml.cuestionario_test, CuestionarioCustomActivity.class, cantidadDePreguntasAMostrar, R.layout.pregunta_cuestionario_custom_layout, R.layout.item_respuesta_custom_layout);
startActivity(intent);