Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “取消”按钮不起作用_Android_Android Widget_Toast - Fatal编程技术网

Android “取消”按钮不起作用

Android “取消”按钮不起作用,android,android-widget,toast,Android,Android Widget,Toast,当我在stackoverflow搜索toast时,我发现了许多与我的问题有关的东西,但没有一个解决了我的问题。在我的android应用程序中,我应该一个接一个地展示很多祝酒词。然而,当我尝试这么做时,下一个祝酒词会等待当前祝酒词完成。即使我用“取消”来表示敬酒,但在我看来它似乎永远不会起作用。请给我一个确切的解决方案。谢谢 inflater = getLayoutInflater(); backgForToast=(ViewGroup) findViewById(R.id.toast_l

当我在stackoverflow搜索toast时,我发现了许多与我的问题有关的东西,但没有一个解决了我的问题。在我的android应用程序中,我应该一个接一个地展示很多祝酒词。然而,当我尝试这么做时,下一个祝酒词会等待当前祝酒词完成。即使我用“取消”来表示敬酒,但在我看来它似乎永远不会起作用。请给我一个确切的解决方案。谢谢

inflater = getLayoutInflater();
    backgForToast=(ViewGroup) findViewById(R.id.toast_layout_root);
    layout = inflater.inflate(R.layout.toastbackground,backgForToast);
    textForToast = (TextView) layout.findViewById(R.id.text);

    textForToast.setText(toastMessage);
    toast.setGravity(Gravity.TOP|Gravity.LEFT, toastX2-90,toastY2-90);
    toast.setView(layout);
    toast.show();

    Handler handler = new Handler();
    long delay = 500;

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            toast.cancel();
        }
    }, delay);

您需要使用
Toast.makeText
创建一个
Toast
对象,然后才能
cancel()
它。

您需要使用
Toast.makeText
创建一个
Toast
对象,然后才能
cancel()
它。

这是一个取消
Toast
的基本示例:

Toast mytoast;
mytoast = Toast.makeText(getApplicationContext(), "Jorgesys was here!", Toast.LENGTH_LONG);
mytoast.show();
....
....
....
if(CancelToast){
  mytoast.cancel();   //Cancelling the toast!.
}

这是一个取消
Toast
的基本示例:

Toast mytoast;
mytoast = Toast.makeText(getApplicationContext(), "Jorgesys was here!", Toast.LENGTH_LONG);
mytoast.show();
....
....
....
if(CancelToast){
  mytoast.cancel();   //Cancelling the toast!.
}

我用onCreate方法做的,比如toast=newtoast(this);好的,所以您需要调用
toast.makeText(this,toastMessage,toast.LENGTH\u LONG)cancel()
之前,请执行code>(或类似操作)。但我使用的是自定义toast。。。我在toast中膨胀了一个视图,我在onCreate方法中这样做,toast=newtoast(this);好的,所以您需要调用
toast.makeText(this,toastMessage,toast.LENGTH\u LONG)cancel()
之前,请执行code>(或类似操作)。但我使用的是自定义toast。。。我用吐司吹出一个观点