我真的很累,我在onPostExecute中将此代码连接到正在下载图像的AsyncTask。问题是烤面包显示大小小于20000字节,但materialdialog从未显示出来,就像if语句为false,即使烤面包正在确认它为真

File imgFile = new File(getApplicationInfo().dataDir+"/files/"+imageNr+".jpg");
double bytes = imgFile.length();
Toast.makeText(getApplicationContext(), ""+bytes, Toast.LENGTH_LONG).show();

if (bytes<20000.0){
    new MaterialDialog.Builder(MainActivity.this)
            .title("Oh no!")
            .content("We've run out of pictures! Would you like to start over or check if a new picture has been uploaded?")
            .positiveText("Check again")
            .negativeText("Start over")
            .callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    getImage();
                }

                @Override
                public void onNegative(MaterialDialog dialog) {
                    int imageNr=1;
                    SharedPreferences.Editor editorsave = sharedPreferences.edit();
                    editorsave.putInt("ImageNr", imageNr);
                    editorsave.apply();
                    getImage();
                }
            });


} else {
    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    imageView.setImageBitmap(myBitmap);

    // Do stuff here
}

最佳答案

呼叫MaterialDialog.Builder.show()。除非它不会出现。

        new MaterialDialog.Builder(MainActivity.this)
                .title("Oh no!")
                .content("We've run out of pictures! Would you like to start over or check if a new picture has been uploaded?")
                .positiveText("Check again")
                .negativeText("Start over")
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        getImage();
                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        int imageNr=1;
                        SharedPreferences.Editor editorsave = sharedPreferences.edit();
                        editorsave.putInt("ImageNr", imageNr);
                        editorsave.apply();
                        getImage();
                    }
                }).show();

10-02 11:35