user3317993
user3317993

Reputation: 111

Android How can I show a Toast?

I have this button, when it's pressed the image will be saved into the external storage. I want to show a Toast with the text "Your photo has been saved".

Here's my code (but it doesn't show the toast whenever I click save):

save.setOnClickListener(new View.OnClickListener() {
    @SuppressLint("ShowToast")
    @SuppressWarnings("deprecation")

    public void onClick(View v) {
        Log.v(TAG, "Save Tab Clicked");

        viewBitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
        canvas = new Canvas(viewBitmap);

        tapimageview.draw(canvas);
        canvas.drawBitmap(bp, 0, 0, paint);
        canvas.drawBitmap(drawingBitmap, matrix, paint);
        canvas.drawBitmap(bmpstickers, matrix, paint);

        //tapimageview.setImageBitmap(mBitmapDrawable.getBitmap());  
        try {
            mBitmapDrawable = new BitmapDrawable(viewBitmap);

            mCurrent = "PXD_" + new SimpleDateFormat("yyyyMMdd_HHmmss",
                Locale.getDefault()).format(new Date()) + ".jpg";

            bp1 = mBitmapDrawable.getBitmap();
            tapimageview.setImageBitmap(bp1);
            mNewSaving = ((BitmapDrawable) mBitmapDrawable).getBitmap();

            String FtoSave = mTempDir + mCurrent;
            File mFile = new File(FtoSave);
            mFileOutputStream = new FileOutputStream(mFile);
            mNewSaving.compress(CompressFormat.JPEG, 100, mFileOutputStream);

            mFileOutputStream.flush();
            mFileOutputStream.close();

        } catch (FileNotFoundException e) {
            Log.v(TAG, "FileNotFoundExceptionError " + e.toString());
        } catch (IOException e) {
            Log.v(TAG, "IOExceptionError " + e.toString());
        }

        Toast.makeText(getApplicationContext(), "Your photo has been saved", Toast.LENGTH_LONG);
    }
});

Upvotes: 0

Views: 178

Answers (4)

M D
M D

Reputation: 47817

You forget .show() in Toast like below:

   Toast.makeText(getApplicationContext(), "Your photo has been saved", Toast.LENGTH_LONG).show();

You can display the toast notification with show().

Upvotes: 4

userAndroid
userAndroid

Reputation: 586

just replace this line

 Toast.makeText(getApplicationContext(), "Your photo has been saved", Toast.LENGTH_LONG);

By this line

 Toast.makeText(getApplicationContext(), "Your photo has been saved", Toast.LENGTH_LONG).show();

Upvotes: 0

Siddharth_Vyas
Siddharth_Vyas

Reputation: 10100

Its strange that the Toast did not show an error. :) You need to add show() at the end.

Toast.makeText(getApplicationContext(), "Your photo has been saved", Toast.LENGTH_LONG).show();

Upvotes: 0

Kanaiya Katarmal
Kanaiya Katarmal

Reputation: 6118

.show() in Toast

 Toast.makeText(getApplicationContext(), "Your photo has been saved", Toast.LENGTH_LONG).show();

Upvotes: 0

Related Questions