Titanium &引用;按键事件“;在appcelerator中,android无法在iPhone模拟器中正常工作

Titanium &引用;按键事件“;在appcelerator中,android无法在iPhone模拟器中正常工作,titanium,appcelerator,appcelerator-titanium,Titanium,Appcelerator,Appcelerator Titanium,我参考了appcelerator官方网站并实现了文本字段,在该字段中,我已将“focusable”属性设置为true,并添加了按键事件,但它不起作用。请提供详细的解决方案? index.xml: <Text Field id="txt_field" focusable = true/> 首先,xml中似乎有一个空格,不确定这是否是输入错误。应该是这样的: <TextField id="txt_field" focusable="true" /> 然后,您需要在控

我参考了appcelerator官方网站并实现了文本字段,在该字段中,我已将“focusable”属性设置为true,并添加了按键事件,但它不起作用。请提供详细的解决方案?

index.xml:

<Text Field   id="txt_field" focusable = true/>

首先,xml中似乎有一个空格,不确定这是否是输入错误。应该是这样的:

<TextField  id="txt_field" focusable="true" />
然后,您需要在控制器中创建changeTextField函数:

function changeTextField(e) {
    // the textfield will be in e.source
    // the new value of the textfield will be in e.value
}

基于此,您可以检查e.value,查看与上次更改相反的更改。

有一个更正。$。txt_field.addEventListener(“按下键”,函数(e){Ti.API.info(“keyCode=“+e.keyCode”);});我已经回答了,但是你完全不清楚你想要实现什么,以及你是如何发现它不起作用的。所以我不得不猜一个比特是的,这是一个打字错误,但是如果我需要键盘值的键码呢。在这种情况下,如何使用更改事件而不是按键?比较更改前后的值以检测键入的内容。你不会像在HTMLTanks中那样在虚拟键盘上获得与@Rene Pot联系的键码,但在iOS中,使用虚拟键盘,按键事件可以正常工作,我可以通过“e.keycode”获得键码值。在安卓系统中,当我尝试时,情况并非如此。即使在按照appcelerator站点中的指示将focusable值设置为true之后。
<TextField  id="txt_field" focusable="true" onChange="changeTextField" />
function changeTextField(e) {
    // the textfield will be in e.source
    // the new value of the textfield will be in e.value
}