Textfield on TableView loses focus (Android)

A tabgroup with 2 tabs has a tableview on the 2nd tab with a textfield on a row.
After a touch on the textfield the keyboard pops up but then the textfield loses focus(ie. there is no cursor in the field).

(Also when using Ti.UI.KEYBOARD_NUMBERS_PUNCTUATION, it only pops up after touching the textfield the second time.)

Any ideas?


var win1 = Ti.UI.createWindow({})
var tab1 = Ti.UI.createTab({
    window: win1

var win2 = Ti.UI.createWindow({})
var row = Ti.UI.createTableViewRow({})
var tF = Ti.UI.createTextField({value: ''})
var tV = Ti.UI.createTableView({data:[row]})

var tab2 = Ti.UI.createTab({  
    window: win2

var tabGroup = Ti.UI.createTabGroup()
tabGroup.addTab( tab1 )
tabGroup.addTab( tab2 )
tabGroup.open({ })

Titanium SDK 1.6.1, Android SDKs: APIs 2.2 / APIs 2.3.1

— asked 5 years ago by J H
  • In order for someone to advise you about this, you need to create a usecase. A usecase is a self-contained piece of code that demonstrates your issue in the least possible number of lines while also running without modification when it is pasted into a bank app.js. Some additional advantages of providing a usecase are:

    • it is much kinder to those wishing to help you, because they won't have to spend considerable time replicating your issue on their systems
    • you will gain a much great knowledge of how Titanium works
    • the process of creating a usecase can often simplify the problem and consequently reveal the answer

    You can read more about this subject in the official documentation, under the section Creating Good Use-cases.

    Note that, if the code is long, you may want to create a Git Gist or pastebin rather than paste the code here directly.

    — commented 5 years ago by Paul Dowsett
  • s/bank/blank :)

    — commented 5 years ago by Paul Dowsett
  • took me 8 hours of wrestling with the Android emulator, but that's one sexy usecase!

    — commented 5 years ago by J H
  • That is indeed a great usecase, JH. I will check it out and let you know.

    — commented 5 years ago by Paul Dowsett

13 Answers

  • I noticed that Android textField events are erratic, including loosing focus immediately after focussing making input impossible. They seem to be especially bad in a tableViewRow.

    So to filter out junk events I've done this:

    textfield.addEventListener('focus', function() {
        var that = this;
        this.focus_timer = setTimeout( function() {
            // True focus commands here
            that.focus_timer = 0;
        }, 500);
        if(this.blur_timer > 0) {
            this.blur_timer = 0;
    textfield.addEventListener('blur', function() {
        var that = this;
        this.blur_timer = setTimeout( function() {
            // True blur commands here
            that.blur_timer = 0;
        }, 500);
        if (this.focus_timer > 0) {
            this.focus_timer = 0;

    Hope this helps.

    — answered 4 years ago by Dan Frist
    • Worked great! Thanks.

      — commented 3 years ago by Allan Brazute
    • Ok, worked to my device (Galaxy Nexus 4.22) but not to a LG device (4.0.4). :(

      — commented 3 years ago by Allan Brazute
    • It worked great to me too! thanks!

      — commented 2 years ago by Manuel Barroso
  • The issue I was running into wasn't exactly as detailed in original posting since I wasn't using a tabbed view but instead opening a new window. I managed to workaround the problem by making that window modal, not sure if that helps you at all or not.

    — answered 4 years ago by Ryan Needham
    • Helped me, thanks!

      — commented 4 years ago by Jeff Cross
    • I tried it, although using a modal window is not an option for me (I need the back-button to work), but it didn't work as well… even with a modal window :(

      — commented 4 years ago by Simon Lipke
  • I am also facing cursor problem. That is there is no cursor in textfield. But losing focus immediately can be solved by just adding a single line in Ti.UI.createWindow.

    var win = Ti.UI.createWindow({
        windowSoftInputMode: Ti.UI.Android.SOFT_INPUT_ADJUST_PAN,
        // other properties
  • Here is a fix for this…


    by no means is this ideal, but in my issue, the keyboard always stayed up but the field only lost focus. So I simply did a check after half a second… and re focused the field. The user wouldn't really even notice.

    — answered 3 years ago by Lee Bartelme
    1 Comment
    • This worked for me. Like you say, it's not ideal, but it works. Thanks

      — commented 3 years ago by Seth Davis
  • This issue is considered "won't fix" as putting a textField inside a table row considered 'bad practice".
    A relevant solution could be using a scrollView instead of the the table.
    See this ticket for more details https://jira.appcelerator.org/browse/TIMOB-8869

  • JH

    I have summarized your two issues in tickets #3451 and #3452. You can log in and click the watch button, if you want to show your support for fixes and be kept up to date about their resolution.


    — answered 5 years ago by Paul Dowsett
    1 Comment
    • Oh, one thing, remember to check your code for syntax errors. Use a validator if possible.


      — commented 5 years ago by Paul Dowsett
  • Try insert a View inside the Window and the TableView inside the View. It works for me.

    var self = new Window();
    var viewContainer = new View({
        top : '10dp',
        bottom : '10dp'
    var tableView = new TableView();
    — answered 3 years ago by Bruno Albano de Souza
    1 Comment
    • This did not work for me. I have same issue. Window -> TableView -> Row -> textField first click always causes keyboard to go up then back down on simulator. Haven't tested on a device yet as I do not have home.

      — commented 3 years ago by Lee Bartelme
  • bumping my new usecase

  • I also ran into this problem today, is there any news on this? Thanks!

  • I have also been fighting with this problem. Is there any update or news on this?

  • has anybody found a workaround for this? (i've been trying to fix this for three months now… no success). Has anybody opened a ticket on the new issue tracker jira.appcelerator.org (i can't find a corresponding ticket to this problem…) ?

  • Same situations,,,, I found the first tab was getting focus, and immidately getting 'blur' again…. so the textfield is loosing focus after the first tab got focus. But the textfield do not get focus again automatically. I don't know why this happens,,,, and difficult to solve….