我想使用钛处理文本字段上的后退按钮。
我知道有一个事件android:返回窗口,但它不会在文本字段上触发。
如何使用钛处理文本字段上的后退按钮(或键盘隐藏事件)?
编辑:这里有一些代码和说明来说明我想说的话:
var textfield = Ti.UI.createTextfield();
textfield.addEventListener('android:back', function() {
// this method is never called, so this event does not run on textfield
});
textfield.addEventListener('focus', function() {
// this method is called at step 1
});
textfield.addEventListener('blur', function() {
// this method is not called at step 2 because
// the back button only hide the keyboard but the focus is not lost
});
// what code should I use to catch event when the keyboard is hidden
// when pressing the back button ?
答案 0 :(得分:0)
键盘关闭时会触发blur
事件。 Here is the doc for it.
假设您创建了textField
类型的Titanium.UI.TextField
对象,您可以非常轻松地收听它:
textField.addEventListener('blur', function(e) {
var val = e.value; // Get current value when the keyboard closed (the right way) as opposed to textField.value (the wrong way)
alert("The text is : "+value);
});
如果您想收听android:back
事件,您必须在窗口上收听。
var win = Ti.UI.currentWindow;
win.addEventListener('android:back', function(e) {
// do crazy things
});
根据文档,这应该有效,如果不是可能是Titanium的错误?