Home > OS >  I got one button here which is submit, and i wanna remind the user to choose an answer with toast so
I got one button here which is submit, and i wanna remind the user to choose an answer with toast so

Time:02-12

R.id.btn_submit ->{

if(mSelectedOptionPosition == 0){

mCurrentQuestion

when{

mCurrentPosition <= mQuestionsList!!.size ->{

setQuestion()

}else ->{

Toast.makeText(this,

"You have successfully completed the quiz",

Toast.LENGTH_SHORT).show()

}

}

}else-> {

val question = mQuestionsList?.get(mCurrentPosition-1)

if (question!!.correctAnswer != mSelectedOptionPosition){

answerView(mSelectedOptionPosition, R.drawable.wrong_option_border_bg)

}

answerView(question.correctAnswer, R.drawable.correct_option_border_bg)

if(mCurrentPosition == mQuestionsList!!.size) {

btn_submit.text = "FINISH"

}else{

btn_submit.text = "Go to next question"

}

}

CodePudding user response:

When do you want to show toast ,you didn't specify clearly. If you want the user to at least choose an option then simply set a check in the btn_submit clickListener that whether any option is chosen or not ,if not then you can show your toast.

Or you can simply show the toast in

    R.id.btn_submit ->{
    
    if(mSelectedOption == null)
    {
      showToast("your message")
    }
    else{

        if(mSelectedOptionPosition == 0){.....
    .
    .
    .
    .
    }

this if block and check for it at the first when the block starts assuming if the mSelectedOption is null then no option is selected or else do the rest of the checking..

  • Related