【问题标题】:display a toast at the beginning of a method在方法的开头显示祝酒词
【发布时间】:2017-09-04 10:55:01
【问题描述】:

问题很简单 我想在方法的开头显示一个(消息)toast 以等待

private void PartitionShow () {Toast.makeText (getApplicationContext (), "wait processing ...", Toast.LENGTH_LONG) .show ();// the code of my method// ...}

只有这条消息只出现在我的方法代码的末尾

一个可行的解决方案是将代码放在一个类中:

private class DownloadFilesTask extends AsyncTask <String, Integer, String> {}

并在以下位置管理吐司:

protected void onProgressUpdate (Integer ... progress) {}

有兴趣的朋友请看sample code

仅在我的代码中创建对象,将其放置在另一个独立线程中会变得沉重且缓慢

感谢那些会为我找到更简单的解决方案的人?

【问题讨论】:

  • “等待”是什么意思?
  • 为什么不用进度条?

标签: android methods show toast


【解决方案1】:

据我所知。

private void PartitionShow () {Toast.makeText (getApplicationContext (), "wait processing ...", Toast.LENGTH_LONG) .show ();// the code of my method// ...}
//// the code of my method//

将执行一些繁重的任务,例如编写文件或批量数据存储或一些繁重的主线程操作。所以你可能会遇到一些故障。你可以做两件事引入新的AsyncTask 或使用Handler 进行线程操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    相关资源
    最近更新 更多