Привет, Хороший день, это мои условия в моей Button, следующая моя проблема: у меня есть тост, если в радиогруппе ничего не выбрано, тогда она выведет сообщение, но ничего не делает и когда я нажимаю дальше, он переходит к следующему вопросу , что я хотел, когда радиолюбители не выбраны, он просто выведет сообщение, и вопросы будут одинаковыми, и он не будет идти на следующие вопросы, вот код i использовать я думаю, что проблема в том, где я поставить условие, чтобы проверить, если он не имеет какой-либо проверенный ответ ИДК действительно пожалуйста, помогите мнеAndroid Studio Quiz App No Checked Radiobutton
@Override
public void onClick(View v) {
RadioButton uans = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
String ansText = uans.getText().toString();
if (ansText.equalsIgnoreCase(answer[flag2])) {
while (numbers.contains(flag2)) {
flag2 = rnd.nextInt(4);
}
correct++;
coins++;
}
else if ((radioGroup.getCheckedRadioButtonId() == -1)
{
Toast.makeText(getApplicationContext(), "Select an Answer Please", Toast.LENGTH_LONG).show();
}
else
{
wrong++;
}
flag++;
flag2 = rnd.nextInt(4);
if (flag < questions.length)
{
tvQuestion.setText(questions[flag2]);
rb1.setChecked(false);
rb2.setChecked(false);
}
else
{
Intent inResult = new Intent(getApplicationContext(), Results.class);
SharedPreferences saveGame = getSharedPreferences("Game", MODE_PRIVATE);
SharedPreferences.Editor editor = saveGame.edit();
editor.putInt("savedPlayerCredit", credit);
editor.putInt("savedPlayerCoins", coins);
editor.putInt("savedPlayerCorrect", correct);
editor.putInt("savedPlayerWrong", wrong);
editor.apply();
timer.cancel();
startActivity(inResult);
}
}
}
);
}
здесь весь код
package org.intercode.lifeatceu;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.provider.MediaStore;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import java.util.HashSet;
import java.util.Random;
public class levelone extends AppCompatActivity {
TextView tv1, tvCred, tvQuestion, tvTimer;
Button btNext;
RadioButton rb1, rb2;
RadioGroup rg;
LinearLayout ll;
String questions [] = {"Ma. Cristina D. Padolina is CEU's President", "Carlito B. Olaer is the V.P of CEU", "CEU's VISION is to sting every enemy", "One of CEU's Mission is to promote creative and scholarly academic"};
String answer [] = {"True", "False", "False", "True"};
HashSet numbers = new HashSet();
int flag = 0;
Random rnd = new Random();
int flag2 = 0 ;
int correct = 0;
int wrong = 0;
int coins = 0;
int time = 0;
int credit = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_levelone);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
SharedPreferences loadGame = getSharedPreferences("Game", MODE_PRIVATE);
credit = loadGame.getInt("savedPlayerCredit", 0);
time = loadGame.getInt("savedPlayerTime", 0);
tv1 = (TextView) findViewById(R.id.tv1);
tvCred = (TextView) findViewById(R.id.tvCred);
tvQuestion = (TextView) findViewById(R.id.tvQuestion);
tvTimer = (TextView) findViewById(R.id.tvTimer);
rb1 = (RadioButton) findViewById(R.id.rb1);
rb2 = (RadioButton) findViewById(R.id.rb2);
rg = (RadioGroup) findViewById(R.id.rg);
btNext = (Button) findViewById(R.id.btNext);
ll = (LinearLayout) findViewById(R.id.ll);
flag2 = rnd.nextInt(4);
numbers.add(flag2);
tvQuestion.setText(questions[flag2]);
tvCred.setText(String.valueOf(credit));
final CountDownTimer timer = new CountDownTimer(time, 1000)
{
public void onTick (long millisUntilFinished)
{
tvTimer.setText ("Time remaining : " + millisUntilFinished/1000);
}
@Override
public void onFinish() {
Intent inResult = new Intent(getApplicationContext(), Results.class);
SharedPreferences saveGame = getSharedPreferences("Game", MODE_PRIVATE);
SharedPreferences.Editor editor = saveGame.edit();
editor.putInt("savedPlayerCredit", credit);
editor.putInt("savedPlayerCoins", coins);
editor.putInt("savedPlayerCorrect", correct);
editor.putInt("savedPlayerWrong", wrong);
editor.apply();
startActivity(inResult);
}
}.start();
btNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioButton uans = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
String ansText = uans.getText().toString();
if (ansText.equalsIgnoreCase(answer[flag2])) {
while (numbers.contains(flag2)) {
flag2 = rnd.nextInt(4);
}
correct++;
coins++;
}
else if ((rg.getCheckedRadioButtonId() == -1)
{
Toast.makeText(getApplicationContext(), "Select an Answer Please", Toast.LENGTH_LONG).show();
}
else
{
wrong++;
}
flag++;
flag2 = rnd.nextInt(4);
if (flag < questions.length) {
tvQuestion.setText(questions[flag2]);
rb1.setChecked(false);
rb2.setChecked(false);
}
else
{
Intent inResult = new Intent(getApplicationContext(), Results.class);
SharedPreferences saveGame = getSharedPreferences("Game", MODE_PRIVATE);
SharedPreferences.Editor editor = saveGame.edit();
editor.putInt("savedPlayerCredit", credit);
editor.putInt("savedPlayerCoins", coins);
editor.putInt("savedPlayerCorrect", correct);
editor.putInt("savedPlayerWrong", wrong);
editor.apply();
timer.cancel();
startActivity(inResult);
}
}
}
);
}
@Override
public void onBackPressed()
{
}
}
Вы используете 'RadioButton' с' RadioGroup' ..? можете ли вы отправить свой код? – user1140237
Проверьте: http://www.mkyong.com/android/android-radio-buttons-example/ –
хорошо держитесь за плохое сообщение –