[TIMOB-4630] Android: UI.TextField - click event not fired first time
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2012-10-03T21:07:28.000+0000 |
Affected Version/s | Release 1.7.1 |
Fix Version/s | n/a |
Components | Android |
Labels | tbs-1.9.0 |
Reporter | Ivan Skugor |
Assignee | Karl Rowley |
Created | 2011-07-08T01:09:51.000+0000 |
Updated | 2018-05-30T11:01:12.000+0000 |
Description
Hi.
I've noticed a bug with "click" event attached to the text field. It seems that "click" event is triggered after text field has gained focus (so, "click" event is triggered after second click).
Code that demonstrate the bug:
var win = Ti.UI.createWindow({
modal: true
});
var tf = Ti.UI.createTextField({
editable: false,
width: 200
});
tf.addEventListener('click', function() {
Ti.alert('Tf clicked!');
});
tf.addEventListener('focus', function() {
Ti.alert('Tf focused!');
});
win.add(tf);
win.open();
Q/A topics:
http://developer.appcelerator.com/question/122008/android-text-field-click-event
http://developer.appcelerator.com/question/122206/double-click-textfield-in-tableview-to-fire-click-event
If you need more info, please let me know.
Just to add a little, I have seen the same issue in SDK versions 1.6.2 and 1.7.1 in both the android 2.2 and 2.3 emulators. I've also run into the same problem with the application installed on a nook color running 2.2 but oddly enough the click event seems to fire as expected when installed on a DroidX also running 2.2
This may be an issue of interpretation of what is "expected" on the part of the user. If I understand correctly, the observation is that the first click of a textfield generates a focus rather than a click, which seems logical and reasonable to me. Still, I will leave it to the core team to decide.
Ivan, please provide the Titanium SDK build date and hash. Also, does this problem occur in an emulator as well as a physical device?
Hi Paul. Sorry for delay, I couldn't comment on this ticket before. Here is SDK build date and hash Titanium SDK version: 1.7.1 (06/21/11 14:28 1293a6d) and I work on real device (Samsung Galaxy Tab v7).
Is this not being looked into further? Is there a workaround? I'm stilling experiencing this issue, on emulator and devices, some devices can't focus the fields at all.
Android OS is different than iOS in that it has two focus types. Focus and touch focus. The first touch changes focus, it's not a 'click'. Click occurs when the field is clicked either by the dpad, enter key, or touched again after it has focus.
@Steve - you could try to attach "focus" event listener in which you can fire "click" event (or just use "focus" event instead of "click" event). Although, I have to say that when I tried that workaround, "focus" event sometimes got fired without click/touch/whatever when scrolling in scroll view (I didn't try to isolate the issue yet). But this is not ideal solution as I mentioned bellow (despite potential bug), but I can't think of any other workaround. @Don - can we have functionality that "click" event gets fired on first time UI component gets clicked/touched? Although, cross-platform consistency seems justified reason for doing that, I would like to point out that many users (coming from DOM environment) find this behavior unintuitive and misleading (in Q/A links, there is example of this kind of behavior in DOM environment). Also, focus can be gained without clicking/touching the UI component, for example by pressing "Next" keyboard key when there are multiple text fields present, so relying on "focus" event to do some first-time-"click" functionality (when user first time clicks/touches the UI component) is not good practice. I can't think of any solution to do first-time-"click" functionality that would work as expected. Or, if you don't find my reasons valid, this behavior should at least be mentioned in the docs.
Just to add that as a workaround, TextField's "focusable" property can be set to "false", that way TextField won't fire "focus" event, but at least will fire "click" event first time user touches it. Maybe it's not workaround for all situations, but it help me accomplish what I wanted.
Just to add Q/A topic about this issue in cross-platform context: http://developer.appcelerator.com/question/130158/text-field-weirdness-on-ios-simulator-and-differences-to-android-implementation Ignore drama at the end, it has some, IMHO, good technical insights.
Can't reproduce with latest fixes for Android tableview -- TIMOB-12038, TIMOB-6732, and TIMOB-10712. Note that the pull requests for TIMOB-6732 and TIMOB-10712 are stil pending at this time.
I tested with latest 3.0.X SDK. The "focus" event is fired when the app starts without any click. Then a click fires a click event. So I cannot reproduce this issue.
I am still experiencing this issue with current 3.0.X SDK, and multiple Android versions. In my situation, the TextField is not automatically focused when the app is open (as it is not the only element which can have focus). The click event does not fire until after it has focus.
Closing ticket as I am unable to reproduce the issue using the following environment; Pixel (7.1) MacOS 10.11.6 (15G31) Studio 4.8.1.201612050850 Ti SDK 6.0.3 GA Appc NPM 4.2.8 Appc CLI 6.1.0 Ti CLI 5.0.11 Alloy 1.9.5 Arrow 1.10.1 Xcode 8.2 (8C38) Node v4.6.0 Java 1.7.0_80
I have reproduced this situation but it is the default behavior on Android