在Android的土司问题

在Android的土司问题

本文介绍了在Android的土司问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

我在Android的一个新的开发者,我展示一个简单的烤面包,当我点击一个按钮。我的问题是,当我点击一个按钮多次的吐司消息一直显示,直到我到了主屏幕。我想停止敬酒时,我得到了主屏和杀死相应的活动的吐司消息。我附上截图

I am a new developer in Android, I am displaying a simple Toast when I click a button. My issue is when I click on a button multiple times that Toast message keeps displaying until I get to the main screen. I would like to stop the Toast when I get the main screen and kill the Toast message in corresponding activity. I have attached a screenshot

我已经写了code如下:

I have written code as follows:

公共类主要活动扩展{

Dialog d;
Toast t;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

//
//

//
//

    ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

      t = Toast.makeText(Main.this, "you clicked on button![enter image description here][3]", Toast.LENGTH_LONG);
        t.show();

        }
    });


   }
@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    t.cancel();
}

}

请任何人都可以解决?

推荐答案

您好我有同样的问题。的问题是,例如吐司重叠如果你preSS 10倍吐司将保持10×LENGTH_SHORT。我带着唯一的解决办法是控制吐司显示由我自己的时间。当你表现出吐司只是保持跟踪你显示它的最后一次,它仍然在屏幕上不再显示它。在你最糟糕的情况下,吐司将是可见的,只有LENGTH_SHORT时间。

Hi I have the same problem. The problem is that the Toast overlaps e.g. if you press 10 times the Toast will stay 10 x LENGTH_SHORT. The only solution I came with was to control the time the Toast is shown by myself. When you show a Toast just keep a track of the last time you show it, it's still on the screen don't show it again. In your worst case the Toast will be visible only LENGTH_SHORT time.

这篇关于在Android的土司问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 23:03