so i want to use a custom dialog which contains an edittext; and the edittext has a textwatcher to convert the text inside of it. when i click the button for the first time and the dialog shows up, everything is fine but the second time the whole app crashes with this error : "The specified child already has a parent. You must call removeView() on the child's parent first ". i searched and tried almost everything but none of them worked. here is the code:
var dialogView = layoutInflater.inflate(R.layout.dialog, null, false)
var edittext = dialogView.findViewById<EditText>(R.id.alert_edittext)
findViewById<Button>(R.id.total_price_manual_input_button).setOnClickListener {
//edittext=layoutInflater.inflate(R.layout.dialog, null, false).findViewById(R.id.alert_edittext)
val builder = AlertDialog.Builder(this@MainActivity)
builder.setView(dialogView)
.create()
.show()
}
}
i read on some topics that i have to create a new instance of the dialogview every time the dialog is being shown but when i tried to pass the "layoutInflater.inflate(R.layout.dialog, null, false)" directly to the setView(), the textwatcher did not get called.
also i tried to cast the dialogView parent as ViewGroup in order to cal removeView() on it but i got nullPointerException.