如何向Thread添加进度条

时间:2016-08-09 13:11:06

标签: android

我有一个创建位图的线程,大约需要4秒,并且当启动活动程序冻结4秒时。 我想在这个时候使用进度条。我怎样才能在线程中实现? 当我在Thread中添加任何进度条时,我给出了Looper()问题。

我的主题:

Thread t = new Thread(new Runnable() {
            public void run() {
// this is the msg which will be encode in QRcode
                QRcode= QRCodeIDFromActivity;
                qrcodeTextview.setText("QRCodeID:"+QRcode);
                sharedqrtextview.setText(sharedqrfromactivity);
                try {
                    synchronized (this) {
                        wait(10);
// runOnUiThread method used to do UI task in main thread.
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                try {

                                    Bitmap bitmap = null;
                                    bitmap = encodeAsBitmap(QRcode);
                                    qrCodeImageview.setImageBitmap(bitmap);

                                } catch (WriterException e) {
                                    e.printStackTrace();
                                } // end of catch block

                            } // end of run method
                        });

                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

0 个答案:

没有答案