1

I've tried searching for the Java tutorial regarding creating my LottieAlertDialog, but I can't find any. Everywhere it's in Kotlin, but I need the Java code as my project is in Java.

I've tried creating my LottieAlertDialog in this way:

LottieAlertDialog.Builder alert=new LottieAlertDialog.Builder(context,DialogTypes.TYPE_CUSTOM,
                        "social.json") //Here social.json is inside assets folder
                        .setTitle("Social")
                        .setDescription("social");
                alert.build();

But the dialogbox doesn't show, when I run the app. To check whether my alert dialogbox was being created or not I tried testing it by printing the description set in the dialog in a Toast:

Toast.makeText(context,alert.getDescription(),Toast.LENGTH_SHORT).show();

The toast works and its showing "social"! That means the dialog is being created. But unfortunately it doesn't show in my app. What do I do? I've implemented all the dependencies as shown in the below link:

lottiealertdialog

TylerH
  • 20,799
  • 66
  • 75
  • 101

2 Answers2

1

The thing is not related to Kotlin or Java as such, you need to show the dialog once you have built it. So far your code is correct. You just need to show it further like this

LottieAlertDialog.Builder alert = new LottieAlertDialog.Builder(context, DialogTypes.TYPE_CUSTOM,
                "social.json")
                .setTitle("Social")
                .setDescription("Social")
                .build()
                .show();

che10
  • 2,176
  • 2
  • 4
  • 11
  • There is no such method called `show()` in java –  Jun 01 '21 at 00:59
  • @Abhishek That seems highly unlikely since Kotlin code is interoperable with Java, could you please tell then after building, what all methods does IDE show you? – che10 Jun 01 '21 at 04:11
  • `build(), setTitle(), getDescription(), copy()` and many more. But nothing called `show()` –  Jun 01 '21 at 04:13
  • @Abhishek I just checked source code for the `LotteAlertDialog`, it just extends the normal `AlertDialog` class, could you try just building a normal dialog and checking if for that the `show()` method is there. Here is some [reference](https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android) – che10 Jun 01 '21 at 04:26
  • Yes `AlertDialog` has `show()`, but not `LotteAlertDialog`. –  Jun 01 '21 at 04:33
  • @Abhishek, I just checked for myself, the method is there, I am updating the code. You can try to copy paste it directly and it should work. – che10 Jun 01 '21 at 05:48
  • It's ok, I've found the solution –  Jun 01 '21 at 07:00
  • @Abhishek Yes, that is what it was it. We were finishing the command of `build()` as we added semicolon after it. – che10 Jun 01 '21 at 07:06
1

Ok, after much hankering, I finally came to the solution. It's

alert.build().show();