避免Toast重复弹出

Toast.matkText才会创建一个新的实例

private Toast toast = null;

private void checkToastResult() {
    if (toast != null) {
        toast.setText("没有搜索结果");
        toast.setDuration(Toast.LENGTH_SHORT);
    } else {
        toast = Toast.makeText(context, "没有搜索结果", Toast.LENGTH_SHORT);
    }
    toast.show();
}

 

posted @ 2018-01-25 14:33  嘉禾世兴  阅读(240)  评论(0编辑  收藏  举报