Issue
Through a click event, I'm trying to close a Snackbar
whenever it is open. However, for some reason, it doesn't get dismissed, despite opening successfully.
- If the
EditText
is empty, I want theSnackbar
to appear - else if the
EditText
is not empty, I want theSnackbar
to be dismissed
I tried using this, but it didn't work:
if (mSnackbar.isShown) {
mSnackbar.dismiss()
}
Would a callback need to be used in this situation? If yes, I'm not sure where it needs to go.
val mSnackbar = Snackbar.make(mRootView, "Hello World", Snackbar.LENGTH_LONG)
val mEditText = findViewById(R.id.my_edit_text) as EditText
val mBtn = findViewById(R.id.my_btn) as Button
mBtn.setOnClickListener {
if (mTextView.text.isEmpty()) {
mSnackbar.show()
} else {
if (mSnackbar.isShown) {
mSnackbar.dismiss()
}
}
}
Solution
Try something like this.
mBtn.setOnClickListener {
if (mTextView.text.isEmpty()) {
mSnackbar.show()
} else {
mSnackbar.dismiss()
}
}
Answered By - Abedin.Zhuniqi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.