Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4630] Android: UI.TextField - click event not fired first time

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-10-03T21:07:28.000+0000
Affected Version/sRelease 1.7.1
Fix Version/sn/a
ComponentsAndroid
Labelstbs-1.9.0
ReporterIvan Skugor
AssigneeKarl Rowley
Created2011-07-08T01:09:51.000+0000
Updated2018-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.

Comments

  1. Ryan Needham 2011-07-08

    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
  2. Paul Dowsett 2011-07-09

    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.
  3. Paul Dowsett 2011-07-09

    Ivan, please provide the Titanium SDK build date and hash. Also, does this problem occur in an emulator as well as a physical device?
  4. Ivan Skugor 2011-07-28

    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).
  5. Steve Lacey 2011-11-04

    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.
  6. Don Thorp 2011-11-04

    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.
  7. Ivan Skugor 2011-11-07

    @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.
  8. Ivan Skugor 2011-12-19

    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.
  9. Ivan Skugor 2012-01-11

    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.
  10. Karl Rowley 2012-09-26

    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.
  11. Karl Rowley 2012-10-03

    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.
  12. Charles Phillips 2012-10-09

    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.
  13. Lee Morris 2017-03-31

    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
  14. ezefire@gmail.com 2018-05-30

    I have reproduced this situation but it is the default behavior on Android

JSON Source