I want to listen to TextView text changes in my dialog, So
I am using TextWatcher like below:
final View layout = activity.getLayoutInflater().inflate(R.layout.popup_history,
container, false);
final Dialog dialog = new Dialog(context, R.style.full_screen_dialog);
dialog.setContentView(layout);
final Window window = dialog.getWindow();
WindowManager.LayoutParams layoutParams;
if (window != null) {
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT);
layoutParams = window.getAttributes();
if (layoutParams != null) {
layoutParams.windowAnimations = R.style.ChooserStyle;
layoutParams.gravity= Gravity.BOTTOM;
window.setAttributes(layoutParams);
}
}
TextView searchHistoryTV = layout.findViewById(R.id.searchHistoryTV);
searchHistoryTV.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
CharSequence editable = searchHistoryTV.getText();
//thereafter use this CharSequence
}
@Override
public void afterTextChanged(Editable s) {
}
});
dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(true);
dialog.show();
Is there any need to remove TextWatcher when dialog is dismissed i.e. in dialog.setOnDismissListener()?Or what if I don't remove it?
question from:
https://stackoverflow.com/questions/65949801/is-there-any-need-to-remove-textwatcher-when-dialog-is-dismissed-in-android 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…