Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/10/2013, 11:36
Doradiolly
 
Fecha de Ingreso: octubre-2013
Mensajes: 6
Antigüedad: 10 años, 7 meses
Puntos: 0
De acuerdo Cómo correguir un cuestionario o test

Buenas, antes de nada ya que es mi primer post me gustaría dar la enhorabuena por dicho foro y me gustaría unirme a esta comunidad. Decir que me alegro mucho de haber encontrado el foro y me ha ayudado bastante las cuestiones planteadas por otros usuarios.

Ahora voy a comentar mi problema, a ver si alguien puede ayudarme.
He creado una aplicación que dadas dos preguntas con dos “RadioGroup” y marcadas sus respuestas en los “RadioBoton” de dichos RadioGroup me diga la nota pulsando un botton “Corregir”, suponiendo que la respuesta correcta suma 1 y la incorrecta resta 0.5.

He definido un vector de int inicializado con las posibles soluciones dada por lo ID’s de las respuestas “RadioBoton” que he considerado correcta para poder compararlas con las dadas por el usuario y he creado dos switch que dependiendo los ID’s de los “RadioGroup” entra según la respuesta correcta en uno u otro.

Pero la cuestión del problema es el siguiente: No sé cómo enlazar el case de los switch al vector soluciones. Entrandome en las opciones default: de dichos switch y sumándome dos errores. nota = -1.

P.D: Adjunto mis archivos: MainActivity.java y activity_main.xml para mayor aclaración. Cualquier comentario será bien agradecido. Muchísimas gracias por la colaboración de antemano.

MainActivity.java

Código PHP:
package com.example.radiogroup_3;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.app.Activity;

public class 
MainActivity extends Activity implements OnCheckedChangeListenerOnClickListener{
    
TextView tv1;
    
RadioGroup rgPregunta1;
    
RadioGroup rgPregunta2;
    
Button btCorreccion;
    
double nota 0nota1=0nota2=0;

    @
Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
setContentView(R.layout.activity_main);
        
        
tv1=(TextView)findViewById(R.id.tv1);
        
btCorreccion = (ButtonfindViewById(R.id.btnCorregir);

        
rgPregunta1=(RadioGroup)findViewById(R.id.radioGroupPregunta1);
        
rgPregunta2=(RadioGroup)findViewById(R.id.radioGroupPregunta2);
        
        
rgPregunta1.setOnCheckedChangeListener(this);
        
rgPregunta2.setOnCheckedChangeListener(this);
        
        
btCorreccion.setOnClickListener(this);    
    }
    
    
int [] soluciones = new int [] {R.id.radio1B,R.id.radio2B}; // Las soluciones son las respuestas B
    
@Override
    
public void onCheckedChanged(RadioGroup groupint checkedId) {
        
        
int pregunta1 R.id.radioGroupPregunta1;
        
int pregunta2 R.id.radioGroupPregunta2;
        
        switch(
pregunta1){
        case 
0:
            
nota1 = +1;
            
resultado();
            break;
        default:
            
nota1 = -0.5;
            
resultado();
            break;
        }
        
        switch(
pregunta2){
        case 
0:
            
nota2 1;
            
resultado();
            break;
        default:
            
nota2 = -0.5;
            
resultado();
            break;
        }    
    }
    private 
double resultado() {
        
nota nota1 nota2
        return 
nota;    
    }
    
    @
Override
    
public void onClick(View arg0) {
        
tv1.setText("La nota es: "+nota);
        
    }

activity_main.xml

Código PHP:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
xmlns:tools="http://schemas.android.com/tools"
    
android:layout_width="match_parent"
    
android:layout_height="match_parent"
    
android:orientation="vertical"
    
tools:context=".MainActivity" >

    <
TextView
        android
:id="@+id/TextView"
        
android:layout_width="wrap_content"
        
android:layout_height="wrap_content"
        
android:text="Pregunta 1:" />

    <
RadioGroup
        android
:id="@+id/radioGroupPregunta1"
        
android:layout_width="wrap_content"
        
android:layout_height="wrap_content"
        
android:layout_marginTop="15dp" >

        <
RadioButton
            android
:id="@+id/radio1A"
            
android:layout_width="wrap_content"
            
android:layout_height="wrap_content"
            
android:text="A" />

        <
RadioButton
            android
:id="@+id/radio1B"
            
android:layout_width="wrap_content"
            
android:layout_height="wrap_content"
            
android:text="B" />

    </
RadioGroup>
    
    <
TextView
        android
:id="@+id/TextView"
        
android:layout_width="wrap_content"
        
android:layout_height="wrap_content"
        
android:text="Pregunta 2:" />

    <
RadioGroup
        android
:id="@+id/radioGroupPregunta2"
        
android:layout_width="wrap_content"
        
android:layout_height="wrap_content"
        
android:layout_marginTop="15dp" >

        <
RadioButton
            android
:id="@+id/radio2A"
            
android:layout_width="wrap_content"
            
android:layout_height="wrap_content"
            
android:text="A" />

        <
RadioButton
            android
:id="@+id/radio2B"
            
android:layout_width="wrap_content"
            
android:layout_height="wrap_content"
            
android:text="B" />

     
    </
RadioGroup>
    
    <
Button 
        android
:id="@+id/btnCorregir"
        
android:layout_width="wrap_content"
        
android:layout_height="wrap_content"
        
android:text="Corregir"
        
/>

    <
TextView
        android
:id="@+id/tv1"
        
android:layout_width="wrap_content"
        
android:layout_height="wrap_content"
        
android:text="@string/respuesta"
        
android:textSize="20sp" />
    

</
LinearLayout
Un millón de gracias por vuestro tiempo y colaboración