i Created this app but after adding the marks showing feature .....
even with a lot of work i am not able to debug it
They are not letting me post as there is mostly code ( Google Terms of Service Last modified: October 25, 2017 (view archived versions)
Welcome to Google! Thanks for using our products and services (“Services”). The Services are provided by Google LLC (“Google”), located at 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States.
By using our Services, you are agreeing to these terms. Please read them carefully.
Our Services are very diverse, so sometimes additional terms or product requirements (including age requirements) may apply. Additional terms will be available with the relevant Services, and those additional terms become part of your agreement with us if you use those Services.)
package com.example.user.questions;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Arrays;
import static android.widget.Toast.makeText;
import static com.example.user.questions.R.string.your_answer;
public class MainActivity extends AppCompatActivity {
private Button mTrueButton;
private Button mFalseButton;
private TextView mQuestionTextView;
private Button mNextButton;
private static final String TAG = "QuizActivity";
private static final String KEY_INDEX = "index";
private int marksObtained = 0;
private TextView mShowAnswers;
//array for question
private Question[] mQuestionBank = new Question[]
{
new Question( R.string.question_inc , true ) ,
new Question( R.string.question_nda , true ),
new Question( R.string.question_sex , false )
};
private int mCurrentIndex = 0 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
mTrueButton = findViewById( R.id.true_button );
mFalseButton = findViewById( R.id.false_button );
mNextButton = findViewById( R.id.next_button );
mQuestionTextView = findViewById( R.id.questions_text );
mShowAnswers = findViewById( R.id.show_result );
//using nezt button here cause it should implement before setting text og question
updateQuestion();
mNextButton.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length ;
updateQuestion();
showAnswers( mCurrentIndex );
}
} );
mTrueButton.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
checkAnswers( true );
mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length ;
updateQuestion();
showAnswers( mCurrentIndex );
}
} );
mFalseButton.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
checkAnswers( false );
mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length ;
updateQuestion();
showAnswers( mCurrentIndex );
}
} );
}
private void updateQuestion() {
int questions = mQuestionBank[mCurrentIndex].getTextResId();
mQuestionTextView.setText( questions ); }
private void checkAnswers (boolean mUserPressedTrue){
boolean answerIsTrue = mQuestionBank[mCurrentIndex].isAnswerTrue();
int messageResId = 0;
if (answerIsTrue == mUserPressedTrue) {
messageResId = R.string.correct_toast;
marksObtained = marksObtained + 1 ;
} else {
messageResId = R.string.wrong_toast;
}
Toast.makeText( this , messageResId , Toast.LENGTH_SHORT ).show();
}
@Override
public void onSaveInstanceState (Bundle savedInstanceState){
super.onSaveInstanceState( savedInstanceState );
savedInstanceState.putInt( KEY_INDEX , mCurrentIndex );
}
public void showAnswers (int var){
if (var == 2) mShowAnswers.setText( marksObtained );
}
}