Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Giving a SearchBar focus does not open the keyboard

Hi,

I have a view where I would like the SearchBar to have focus when it's loaded, I've achieved this by calling the focus() method on the SearchBar in response to a Window open event. The problem is that even though it has focus the keyboard isn't displayed so the text box still needs another click, defeating the purpose.

Is there anyway around this?

Regards,

Chris

— asked May 24th 2010 by Chris Brown
  • keyboard
  • mobile
0 Comments

2 Answers

  • That is exactly what I do and works for me. Here is the code sample:

    var win = Titanium.UI.currentWindow;
    //
    //Create the Search Bar 
    // 
    var search = Titanium.UI.createSearchBar({ 
        showCancel:true,
        height:43,
        top:0,
        barColor:'#000',
        zindex:1
    });
    
    win.add(search);
    
    // set the focus on the search bar as soon as the window opens
    win.addEventListener('open', function(e)
    {
        Ti.API.info('Search window just opened');
        search.focus();
    });
    
    — answered May 24th 2010 by Antonio Silveira
    permalink
    0 Comments
  • Thanks Antonio, but that doesn't work for me. I'm using the android emulator.

    — answered May 24th 2010 by Chris Brown
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.