Reputation: 95
I am getting really tired, I have this code in the onPostExecute connected to a AsyncTask that is downloading an image. The thing is the toast is showing that the size is below 20000 bytes but the materialdialog never shows up, its like the if statement is false even though the toast is confirming that it is true
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
}
Upvotes: 1
Views: 100
Reputation: 2693
You are missing to call show()
in 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
as AlertDialog
is now also available with AppCompat
v21.
compile 'com.android.support:appcompat-v7:22.2.0'
Upvotes: 0
Reputation: 2806
call MaterialDialog.Builder.show()
. unless it wont show up.
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();
Upvotes: 1