首页 \ 问答 \ UI线程与其他线程之间使用处理程序进行通信(Communication between UI thread and other threads using handler)

UI线程与其他线程之间使用处理程序进行通信(Communication between UI thread and other threads using handler)

如何在UI线程和后台线程之间进行线程间通信? 我想在这里使用通用处理程序概念来更新我的UI。 我有如下概念

new Thread(new Runnable() {
         public void run() {
             while (mProgressStatus < 100) {
                 mProgressStatus = doWork();

                 // Update the progress bar
                 mHandler.post(new Runnable() {
                     public void run() {
                         mProgress.setProgress(mProgressStatus);
                     }
                 });
             }
         }
     }).start();

我想使用两个类,一个类包含主线程,另一个类包含后台线程,它们使用相同的处理程序。 我该如何实现? 我知道这很常见,但我发现很难完全实现。


How to do inter thread communication between UI thread and background thread? I want use common handler concept here to update my UI. I have the concept as below

new Thread(new Runnable() {
         public void run() {
             while (mProgressStatus < 100) {
                 mProgressStatus = doWork();

                 // Update the progress bar
                 mHandler.post(new Runnable() {
                     public void run() {
                         mProgress.setProgress(mProgressStatus);
                     }
                 });
             }
         }
     }).start();

I want to use two classes, one class contains main thread, another class contains background thread and they use the same handler. How do I implement this? I know it is very common but I am finding it difficult to exactly implement.


原文:https://stackoverflow.com/questions/42475812
更新时间:2023-12-11 10:12

最满意答案

我建议pyPdf 。 它的工作非常好 前几天我也写了一篇博文,你可以在这里找到。


I suggest pyPdf. It works really nice. I also wrote a blog post some while ago, you can find it here.

相关问答

更多
  • 你可以使用matplotlib pgf后端来做到这一点。 然后你可以在序言中使用不同的包。 在这种情况下,我正在使用pdfcomment。 这是一个非常简单的例子,但我认为你可以从这里出发! import matplotlib as mpl mpl.use("pgf") pgf_with_pdflatex = { "pgf.texsystem": "pdflatex", "pgf.preamble": [ r"\usepackage[author={me}]{pdfcomme ...
  • 我建议pyPdf 。 它的工作非常好 前几天我也写了一篇博文,你可以在这里找到。 I suggest pyPdf. It works really nice. I also wrote a blog post some while ago, you can find it here.
  • 我以前做过这个。 我有一个使用fpdf生成的pdf,我需要添加一个可变量的PDF。 所以我已经有一个fpdf对象和页面设置(http://www.fpdf.org/)我使用fpdi来导入文件(http://www.setasign.de/products/pdf-php-solutions/ fpdi /)通过扩展PDF类添加FDPI: class PDF extends FPDI { } $pdffile = "Filename.pdf"; $pagecount = $pdf-> ...
  • 想到的两个是: pyPdf2 PDFMiner The two that come to mind are: pyPdf2 PDFMiner
  • 从ask.yahoo借来的 如果PDF文件是1.1版本的PDF文件,则该文件以“%PDF-1.1”开头。 如果没有存储二进制数据对象,您可以阅读PDF文件,如果您不需要在其中存储二进制对象,例如绘制位图,则甚至可以使用记事本制作一个。 但在看到“%PDF-1.1”后,忽略之后的内容(Adobe Reader也会这样做),直接到文件末尾,在那里有一行说“%% EOF”。 这总是文件中的最后一件事; 如果在那里,你知道在文件之前只有几个字符,那么后面跟着一个数字就是“startxref”。 该数字告诉读者程序在 ...
  • 有一个解决方案 。 如果我没记错的话,关键点是: 使用特殊的目录作为主文档(我使用index_TOC.rst而不是默认的index.rst ):在conf.py master_doc = 'index_TOC' latex_documents = [('index_TOC', 'uncertaintiesPythonpackage.tex',…] 新的目录文件index_TOC.rst包含ToC之类的 TOC === .. toctree:: :hidden: :maxdepth: 1 ...
  • 在您的第一个块中,以二进制写入模式(wb)打开文件,因为您正在向其写入二进制文件。 另外,你不需要将它明确地转换为str。 它应该是这样的: file = open('code.txt', 'wb') for line in open('somefile.pdf', 'rb').readlines(): file.write(line) file.close() 对于第二个块,以读取二进制模式(rb)打开文件。 这里也不需要显式地转换为字节。 它应该是这样的: file = open('new.p ...
  • 编辑:我刚刚遇到了兼容Python 3的Django Easy PDF,可能更有用: https://github.com/nigma/django-easy-pdf 但请注意,在编写此xhtml2pdf时 ,如果您安装最新的beta版本,那么Django Easy PDF的依赖项仅支持Python 3: pip install --pre xhtml2pdf WeasyPrint与Python 3兼容: http://weasyprint.org/ 它是一个很棒的库,很容易与Django集成。 这是一篇 ...
  • 下面的代码应该正确地对完整的文件名进行排序,假设您更新的代码(基于salomonderossi和Byte Commander的答案中的代码)确实显示了正确的常用文件名部分。 请注意,此代码未经测试。 如果您在问题中提供了一小组典型的文件名,那么我们写答案会更容易。 这不仅有助于我们更好地理解任务,而且还可以更轻松地测试我们的代码。 import os import fnmatch files_result = [] for root, dirnames, files in os.walk(r'C:\PAT ...
  • 好吧,我终于找到了解决方案, 我使用了Request和StringIO并取消了open('my_file', 'rd')命令 from urllib2 import Request from StringIO import StringIO url = 'my_url' open = urllib2.urlopen(Request(url)).read() memoryFile = StringIO(open) parser = PDFParser(memoryFile) 这样Python就将url ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。