我真的很累,我将onPostExecute中的代码连接到正在下载图像的AsyncTask。事情是吐司显示大小低于20000字节,但materialdialog从未出现,就像if语句是假的,即使吐司确认它是真的
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
}
答案 0 :(得分:1)
致电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();
答案 1 :(得分:0)
您错过了在show()
中致电MaterialDialog.Builder
。
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();
MaterialDialog
AlertDialog
现在也可以AppCompat
v21使用。
compile 'com.android.support:appcompat-v7:22.2.0'