Toasts do not show up


#1

QuizActivity.java:

[code]package com.bignerdranch.android.geoquiz;

import android.app.;
import android.os.
;
import android.view.;
import android.widget.
;

public class QuizActivity extends Activity
{
private Button mTrueButton;
private Button mFalseButton;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz);
	
	mTrueButton = (Button)findViewById(R.id.true_button);
	mTrueButton.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
			}
		});

	mFalseButton = (Button)findViewById(R.id.false_button);
	mFalseButton.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			Toast.makeText(QuizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show();
			}
		});
	
}

}[/code]
I am using AIDE, an app-creating app, on an unrooted Samsung Galaxy Tab 3 running Android 4.1.2. Anyone know why my toasts don’t show up? If you need to see any other files’ codes, just ask :smiley:


#2

Maybe because you didn’t import Toast?

Does AIDE have something to organize imports? If not, you might want to try Eclipse, it practically writes the Imports for you when you do Ctrl + Shift + O.


#3

Yes, it has import organizers. What it does, though, is makes the asterisks after everything. I guess AIDE thinks that the asterisks are used to represent everything that you need?


#4

Upon clicking true or false button the Toast popup is not showing up.
Upon clicking the button control jumps to the button tag in activity_quiz.xml
–Any pointers are appreciated. Thanks…

Debug steps done:
a)The QuizActivity.java does have the "import android.widget.Toast;"
b)confirmed stirng.xml and java files are correct
c)Ran clean build
d)Restarted eclipse

here is my string.xml and java snippets:

<?xml version="1.0" encoding="utf-8"?>
<string name="app_name">GeoQuiz</string>
   <string name="action_settings">Settings</string>
<string name="question_text">constantinople is the largest city in Turkey</string>

True
False
Correct!
Incorrect!!

package com.bignerdranch.android.geoquiz;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class QuizActivity extends Activity {

Button mTrueButton;
Button mFalseButton;

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

    mTrueButton = (Button)findViewById(R.id.true_button);
    mTrueButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(QuizActivity.this, 
                    R.string.incorrect_toast, Toast.LENGTH_SHORT)
                    .show();
        }
    });

    mFalseButton = (Button)findViewById(R.id.false_button);		
    mFalseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(QuizActivity.this, 
                    R.string.correct_toast, Toast.LENGTH_SHORT)
                    .show();
        }
    });
}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.quiz, menu);
    return true;
}

}