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