Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello , please help me, I don’t know to solve my code problem about fragments , it is said that the fragments must be static #28

Open
Rmintender opened this issue Feb 1, 2021 · 2 comments

Comments

@Rmintender
Copy link

public OnClickListener guessButtonListener = new OnClickListener() {

    @Override
    public void onClick(View v) {
        Button guessButton = ((Button) v);
        String guess = guessButton.getText().toString();
        String answer = getCountryName(correctAnswer);
        ++totalGuesses; // increment number of guesses the user has made

        if (guess.equals(answer)) { // if the guess is correct
            ++correctAnswers; // increment the number of correct answers

            // display correct answer in green text
            answerTextView.setText(answer);


            disableButtons(); // disable all guess Buttons

            // if the user has correctly identified FLAGS_IN_QUIZ flags
            if (correctAnswers == FLAGS_IN_QUIZ) {
                // DialogFragment to display quiz stats and start new quiz
                DialogFragment quizResults =
                        new DialogFragment() {
                            // create an AlertDialog and return it
                            @Override
                            public Dialog onCreateDialog(Bundle bundle) {
                                AlertDialog.Builder builder =
                                        new AlertDialog.Builder(getActivity());
                                builder.setMessage(
                                        getString(R.string.results,
                                                totalGuesses,
                                                (1000 / (double) totalGuesses)));

                                // "Reset Quiz" Button
                                builder.setPositiveButton(R.string.reset_quiz,
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog,
                                                                int id) {
                                                resetQuiz();
                                            }
                                        }
                                );

                                return builder.create(); // return the AlertDialog
                            }
                        };
@Rmintender
Copy link
Author

image

@paulsoja
Copy link

paulsoja commented Feb 1, 2021

public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Важное сообщение!")
.setMessage("Покормите кота!")
.setIcon(R.drawable.ic_launcher_cat)
.setPositiveButton("ОК", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
return builder.create();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants