简体   繁体   English

Android:ProgressDialog Circle不显示

[英]Android: ProgressDialog Circle not showing

I tried to implement a loading circle in my application as it transitioned from the previous activity to this activity. 我试图在我的应用程序中实现一个加载循环,因为它已从上一个活动过渡到了此活动。 As there are a ton of calculations in this activity, it turns black screen as it's doing the calculations for a good 10 to 15 seconds, once the calculations are done it'd display an image, seen in onCreate: resultImage.setImageBitmap(finalBitmap); 由于此活动中有大量计算,它会在进行10到15秒钟的计算时变成黑屏,一旦计算完成,它就会显示图像,如onCreate中所示: resultImage.setImageBitmap(finalBitmap);

However, the circle doesn't appear, and it's still the same old black screen to image transition. 但是,没有出现该圆圈,并且仍然是从旧的黑屏到图像的过渡。

Imported: 进口:

import android.app.ProgressDialog;

Declared: 宣告:

private ProgressDialog progressDialog;

Initialized: 初始化:

progressDialog = new ProgressDialog(this);
        progressDialog.setTitle(null);
        progressDialog.setCancelable(false);

Made it visible: 使其可见:

progressDialog.show();

Changed its message as the code progressed: 随着代码的进行更改了其消息:

progressDialog.setMessage("Finding Objects...");

progressDialog.setMessage("Calculating Areas...");

progressDialog.setMessage("Calculating Height...");

... etc etc ...等

onCreate: onCreate:

@Override
    public void onCreate(Bundle savedInstanceState) {

        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle(null);
        progressDialog.setCancelable(false);

        progressDialog.setMessage("Processing...");
        progressDialog.show();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auto_test);



        if (!OpenCVLoader.initDebug()) {
            Log.d("opencv", "OpenCVLoader.initDebug() - ERROR");
        } else {
            Log.d("opencv", "OpenCVLoader.initDebug() - OK");
        }


        String filePath = getIntent().getStringExtra(FILEPATH);
        ArrayList<String> f = new ArrayList<String>();

        File dir = new File(filePath);
        File[] listFile;

        listFile = dir.listFiles();

        for (File e : listFile) {
            f.add(e.getAbsolutePath());

        }


        paths = f;


        resetVariables();
        progressDialog.setMessage("Finding Objects...");
        for (int xx = 0; xx < paths.size(); xx++) {
            Bitmap areaBitmap = BitmapFactory.decodeFile(paths.get(xx));
            getArea(areaBitmap);

        }
        if (loopCounter > 0) {
            progressDialog.setMessage("Calculating Areas...");
            meanBlackArea = blackArea / loopCounter;

            Log.e("meanBlackArea", "30% of mean black " + String.valueOf(meanBlackArea * 0.3) + " 110% of mean black " + String.valueOf(meanBlackArea * 1.1));
            Log.e("Loopcounter", String.valueOf(loopCounter));
        }
        resetVariables();


        Log.e("~", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        Log.e("Lowest Green", String.valueOf(greenArea));
        Log.e("~", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        progressDialog.setMessage("Calculating Height...");

        int frameNumber = 0;
        for (int x = 0; x < paths.size(); x++) {

            Bitmap calculationsBitmap = BitmapFactory.decodeFile(paths.get(x));
            numRectBlack = 0;
            numRectGreen = 0;

            tempBitmap = findCombineBitmap(calculationsBitmap);
            if (check == true) {
                if (Double.isInfinite(tempLineHeightCm) == false) {
                    frameNumber = x;
                    finalBitmap = tempBitmap;
                }
            }

        }
        progressDialog.setMessage("Tidying Up...");
        TextView tvR = (TextView) findViewById(R.id.tvR);
        if(tempLineHeightCm==0) {
            tvR.setText("We could not detect a bounce!\nPlease do the following and try again:\n1. Remove all foreign objects from testing grounds.\n2.Make sure that there are ample lighting on the testing grounds.");
        }else{
            tvR.setText("Frame " + frameNumber + ", Bounce Height = " + tempLineHeightCm + "cm");

            ImageView resultImage = (ImageView) findViewById(R.id.resultImage);

            resultImage.setImageBitmap(finalBitmap);
            progressDialog.dismiss();
        }

    }

Link to code file: 链接到代码文件:

Google Drive Google云端硬碟

Notes: 笔记:

  1. MainActivity.java has a working progresscircle MainActivity.java可以正常工作
  2. TestAutoRun.java is the one I'm working on. TestAutoRun.java是我正在研究的那个。

Show ProgressDialog , start new AsyncTask and do your heavy calculations in background. 显示ProgressDialog ,启动新的AsyncTask并在后台进行大量计算。 After the AsyncTask completes, hide the progress dialog and go to next activity. AsyncTask完成后,隐藏进度对话框并转到下一个活动。

If you don't know how to use AsyncTask , check the reference here. 如果您不知道如何使用AsyncTask ,请在此处查看参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM