I want to cancel a Toast to show the next one. This is the description
of the behavious I want, when I select one element in the menu i
display a toast from the actuel menu element, but if i switch from one
element to an other quickly  i'm creating a list of Toast to display.
So i need to cancel the previous one but i never succed.


This is an extract of my code:
public class MainActivity extends TabActivity {

    private Toast toast;
    private String toastMsg;

    private void toast(){
        if(toast!=null){
                        toast.cancel();
                }
                toast = Toast.makeText(MainActivity.this,
toastMsg,Toast.LENGTH_SHORT);

                toast.show();
    }
}
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                final TabHost tabHost = getTabHost();
                final TabWidget tabWidget = getTabWidget();



                tabWidget.setOnItemSelectedListener(new 
OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> arg0, View 
arg1,
                                        int arg2, long arg3) {
                                tabHost.setCurrentTab(arg2);
                                toastMsg = "New Tab"+arg2;
                                toast();
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {

                        }
                });
}
}

The cancel method is call everytime it's needed but it do nothing like
it wasn't call. I try this on different android version from 1.5 to
2.2 but nothing change, I also try on an phone.

I look into the google android sample code given with the sdk and I
found AlarmController who is using the cancel method from a Toast but
it's doing the same behaviour problem.

Does anyone already have this trouble and solved it?
I will be happy to receive any proposition who can solved my problem.

Sorry for my English who isn't so good.

Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to