android - 检测 EditTextPreference 上的负按钮按下
问题描述
我有一个带有 EditTextPreference 的 PreferenceActivity。我可以很容易地检测到积极的按钮按下使用OnPreferenceChangedListener
。但是,当用户按下否定按钮时,永远不会调用侦听器。
反正有检测吗?谢谢。
解决方案
onDialogClosed(...)
除非您覆盖in EditTextPreference
(假设您使用旧的且现已弃用的框架版本的首选项),否则您无法检测到它:
public class EditTextPreferenceNegative extends EditTextPreference {
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult); // this will notify the change listener for positive results
if (!positiveResult) {
// do something with your negative result
}
}
}
但是请注意,即使对话框在没有按下否定按钮的情况下关闭,也会调用它。如果您只想检测否定按钮,您可以覆盖onClick(...)
单击任一按钮时调用的方法。
推荐阅读
- node.js - Visual Studio Code 调试环境的退出处理程序
- php - Laravel 图像 404 未找到
- php - 如何显示 Google Drive 文件夹中的图像?
- php - 动态表单未正确提交 AJAX PHP
- text-files - 如何在 jupyter notebook 中使用 pandas 将文本文件数据转换为表格格式?
- .net-core - 基于环境 .NET Core 隐藏 NSwag 文档端点
- python - 如何在 Python 中使用 pdf 管道工打开多个 pdf 文件?
- reactjs - 如何在formik中创建添加图像输入
- c++ - 在 C++ 中为文件名添加时间戳
- javascript - 将函数作为道具传递,在调用函数时它没有得到正确的值