2016-05-13 9 views
0

Ich entwickle eine Anwendung für Quiz.in meinem XML habe ich eine Frage, 4 Optionen (Optionen sind Textansichten) und vorherigen und nächsten Tasten. Ich habe vorherige und nächste Tasten gedrückt. aber ich habe Probleme mit Optionen. Wenn ich auf die Option für eine Frage klicke oder wähle, werden auch alle Fragen ausgewählt. Wie kontrolliere ich dieses Verhalten? bitte irgendeine Hilfe, wie man es macht?alle Textansichten werden ausgewählt, wenn eine Textansicht durch Klicken auf Listener in Android auswählen?

if (v == rb1) { 
     Toast.makeText(getApplicationContext(), rb1.getText().toString(), Toast.LENGTH_SHORT).show(); 
     // quelay.setVisibility(View.INVISIBLE); 
     // answer.setVisibility(View.VISIBLE); 
     db.updateContact(question.getText().toString()); 
     setNext(); 
    if (v == rb2) { 
     Toast.makeText(getApplicationContext(), rb1.getText().toString(), Toast.LENGTH_SHORT).show(); 
     // quelay.setVisibility(View.INVISIBLE); 
     // answer.setVisibility(View.VISIBLE); 
     db.updateContact(question.getText().toString()); 
     setNext(); 

Antwort

0

Sie können dies versuchen.

private View.OnClickListener mCorkyListener = new View.OnClickListener() { 
     public void onClick(View v) { 
      // do something when the button is clicked 
      // Yes we will handle click here but which button clicked??? We don't know 

      // So we will make 
      switch (v.getId() /*to get clicked view id**/) { 
       case R.id.rb1: 

        Toast.makeText(getApplicationContext(), rb1.getText().toString(), Toast.LENGTH_SHORT).show(); 
        //quelay.setVisibility(View.INVISIBLE); 
        //answer.setVisibility(View.VISIBLE); 
        db.updateContact(question.getText().toString()); 
        setNext(); 

        break; 
       case R.id.rb2: 

        Toast.makeText(getApplicationContext(), rb2.getText().toString(), Toast.LENGTH_SHORT).show(); 
        //quelay.setVisibility(View.INVISIBLE); 
        //answer.setVisibility(View.VISIBLE); 
        db.updateContact(question.getText().toString()); 
        setNext(); 

        break; 
       case R.id.rb3: 

        Toast.makeText(getApplicationContext(), rb3.getText().toString(), Toast.LENGTH_SHORT).show(); 
        //quelay.setVisibility(View.INVISIBLE); 
        //answer.setVisibility(View.VISIBLE); 
        db.updateContact(question.getText().toString()); 
        setNext(); 

        break; 

       case R.id.rb4: 

        Toast.makeText(getApplicationContext(), rb4.getText().toString(), Toast.LENGTH_SHORT).show(); 
        //quelay.setVisibility(View.INVISIBLE); 
        //answer.setVisibility(View.VISIBLE); 
        db.updateContact(question.getText().toString()); 
        setNext(); 

        break; 
       default: 
        break; 
      } 
     } 
    }; 
0

die Sie interessieren,

if (v == rb1) { 
    Toast.makeText(getApplicationContext(), rb1.getText().toString(), Toast.LENGTH_SHORT).show(); 
    db.updateContact(question.getText().toString()); 
    setNext(); 
if (v == rb2) { 
    Toast.makeText(getApplicationContext(), rb2.getText().toString(), Toast.LENGTH_SHORT).show(); 

    db.updateContact(question.getText().toString()); 
    setNext(); 

zeigen Sie rb1.getText(). ToString() in beiden conditons. so ändern Sie Ihre zweite Bedingung Teil wie,

if (v == rb2) 
Toast.makeText(getApplicationContext(), rb2.getText().toString(), Toast.LENGTH_SHORT).show();