Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Toast Message is not showing

Tags:

android

I have Button.When the user click the button, there are some condition, that condition is not satisfy then need to display Toast but not showing Toast Message...

Code: Edited

 Button addMe = (Button)findViewById(R.id.addMe);     addMe.setOnClickListener(new OnClickListener() {            public void onClick(View v) {                if(selectedReason.equals("--Select--")){                    Log.i("TAG","-----");                    Toast.makeText(getBaseContext(), "Reason can not be blank", Toast.LENGTH_SHORT).show();                }else if(selectedType.equals("--Select--")){                    Toast.makeText(getParent(), "Discount type can not be blank", Toast.LENGTH_SHORT).show();                }else{                    if(selectedType.equals("Value")){                        if(spc_amount.getText().toString().equals("")){                            Log.i("TAG","-----");                            Toast.makeText(getBaseContext(), "Discount type can not be blank", Toast.LENGTH_SHORT).show();                        }else{                            if(Double.parseDouble(spc_amount.getText().toString()) > invoiceValue){                                Toast.makeText(getBaseContext(), "Amonut can not be grater than invoice", Toast.LENGTH_SHORT).show();                            }else{                                Discount dis = new Discount();                                dis.setCriteriaName(selectedReason);                                dis.setDiscountValue(Double.parseDouble(spc_amount.getText().toString()));                                spDisList.put(1,dis);                                tl.removeAllViews();                             loadTableLayout();                            }                         }                    }                }            }     }); 

I have tried context with getParent() , getApplicationContext() , SpecialDiscountActivity.this & getBaseContext() but not working....

This Toast message coming under the Tab Activity Group

like image 851
Piraba Avatar asked Oct 18 '11 06:10

Piraba


People also ask

Why is toast not showing messages?

Make sure not to forget to call show() after the makeText. Check for the Context , if its the right one. The most important one , make sure your Android Notifications are on for your app, else the Toast will not be shown.

How do you show toast on Android messages?

Display the created Toast Message using the show() method of the Toast class. The code to show the Toast message: Toast. makeText(getApplicationContext(), "This a toast message", Toast.

Why is toast not working in Android Studio?

If a toast message is not getting displayed when you run your android Application, 1. Check that you have used . show() method on the toast object as an initial troubleshooting step.


2 Answers

Try:

Toast.makeText(getBaseContext(), "Reason can not be blank", Toast.LENGTH_SHORT).show(); 

It's the .show() that you've omitted everywhere that causes all your toasts to instatiate, but never execute.

like image 138
Pocket Universe Avatar answered Sep 20 '22 19:09

Pocket Universe


Please excuse me if this isn't the solution to your problem, but I accidentally unchecked the 'Show notification' setting of the application once. It may be an idea go into your device settings/application/manager and check this setting.

like image 21
user2288580 Avatar answered Sep 20 '22 19:09

user2288580