问题
So, I'm using Kotlin extensions which is straightforward, but I can't get string from edittext
here is my code:
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val v = activity.layoutInflater
.inflate(R.layout.dialog_group, null)
v.add_group_button.setOnClickListener(addListener)
return AlertDialog.Builder(activity)
.setView(v)
.create()
}
private var addListener: View.OnClickListener = View.OnClickListener {
val groupNameInput: String = view?.group_edit_text?.text.toString()
}
when I'm pressing add button groupNameInput
always returns null why?
回答1:
So finally I figure it out — on Dialog Fragment view will always be null, because its never created, but it's created and added to dialog view which means I need to call:
dialog.group_edit_text.text.toString()
Instead of:
view.group_edit_text.text.toString()
来源:https://stackoverflow.com/questions/47285180/kotlin-dialogfragment-edittext-editable-always-null