吐司没有出现

时间:2015-06-22 01:11:39

标签: android toast

所以,我有import android.widget.toast,编译时没有收到任何错误。但是,以下内容:

private void checkAnswer(boolean userPressedTrue){
    boolean isAnswerTrue = mQuestionBank[mCurrentIndex].isTrueQuestion();

    int messageResId = 0;

    if (userPressedTrue == isAnswerTrue){
        messageResId = R.string.correct_toast;
    } else {
        messageResId = R.string.incorrect_toast;
    }

    Toast.makeText(this.getApplicationContext(), messageResId, Toast.LENGTH_SHORT);

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz);

    mQuestionTextView = (TextView) findViewById(R.id.question_text_view);

    mTrueButton = (Button) findViewById(R.id.true_button);
    mTrueButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkAnswer(true);
        }
    });
    mFalseButton = (Button) findViewById(R.id.false_button);
    mFalseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkAnswer(false);
        }
    });

不会显示在我的手机上。我确保该应用未禁用通知。

1 个答案:

答案 0 :(得分:4)

你需要在makeText();

之后调用show()方法
    Toast.makeText(this.getApplicationContext(), messageResId, Toast.LENGTH_SHORT).show();