0

I create dialog box by extending AppCompatDialogFragment(). I have one EditText field and Positive/Negative button. When I click on the Positive button I want to keep the value on the EditText, so when I reopen the dialog the value will be already written there.

Positive button (inside onCreateDialog()) - I send text to MainActivity

.setPositiveButton("apply", DialogInterface.OnClickListener(){ _: DialogInterface, _: Int ->
            (activity as MainActivity?)?.updateDelay(textDelay.text.toString())
        })
Tugay
  • 2,057
  • 5
  • 17
  • 32
GeoCap
  • 505
  • 5
  • 15
  • Does this answer your question? [How to store edit text data from an Android dialog?](https://stackoverflow.com/questions/27761497/how-to-store-edit-text-data-from-an-android-dialog) – Cyb3rKo Sep 06 '20 at 15:49

2 Answers2

0

You can use an interface which passes the value back if the dialog is closed:
https://stackoverflow.com/a/27761620/9077356

If you want to permanently store the value and use it all around your project, you can also store it in Sharedpreferences.

Here`s an very simple tutorial of how to use SharedPreferences:
https://dev.to/victordgrandis/how-to-store-data-in-sharedpreferences-3a36

Cyb3rKo
  • 413
  • 7
  • 22
0

if you want to save this value while app is open use static value like in JAVA

public static String objectName = "";

and in Kotlin

companion object {

var objectName : String= ""
}
Vikas
  • 432
  • 4
  • 17