Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11627] Android: searchBar.focus() doesn't open the softKeyboard

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-11-02T22:19:21.000+0000
Affected Version/sRelease 2.1.3
Fix Version/s2012 Sprint 23 API, 2012 Sprint 23
ComponentsAndroid
Labelsapi
ReporterNikhil Sharma
AssigneeHieu Pham
Created2012-10-31T22:04:04.000+0000
Updated2014-06-19T12:44:09.000+0000

Description

searchBar.focus() doesn't open the softKeyboard. In the code below if you uncomment the code that adds a tableView the keyboard opens properly. This problem seems to happen with textField as well.

Repo Steps

1. Run the below code in your project's app.js. 2. Open the application. 3. The cursor shows up in the search bar but the keyboard never opens.
Titanium.UI.setBackgroundColor('#000');

var win = Titanium.UI.createWindow({
	backgroundColor : '#fff'
});
var dirView = Ti.UI.createView({
	layout : 'vertical',
	height : Ti.UI.FILL
});

var searchBar = Titanium.UI.createSearchBar({//problem also exists with TextField
	width : Ti.UI.FILL,
	height : 50,
	softKeyboardOnFocus : Ti.UI.Android.SOFT_KEYBOARD_SHOW_ON_FOCUS
});

dirView.add(searchBar);

//the cursor shows up in the search bar but the keyboard never opens
searchBar.focus();

//uncommenting these lines 'fixes' the problem

// var thelist = Titanium.UI.createTableView();
// dirView.add(thelist);

win.add(dirView);
win.open(); 

Comments

  1. Ben Zeghers 2012-11-05

    The code that you posted to fix this issue doesn't work. I put it into the above app.js and the keyboard still doesn't open when I open the app.
  2. Hieu Pham 2012-11-05

    Which build did you test this on? It works fine for me for 2.x, 3.x, and 4.x phones on master. This is the app.js I use:
       Titanium.UI.setBackgroundColor('#000');
        
       var win = Titanium.UI.createWindow({
           backgroundColor : '#fff'
       });
       var dirView = Ti.UI.createView({
           layout : 'vertical',
           height : Ti.UI.FILL
       });
        
       var searchBar = Titanium.UI.createTextField({//problem also exists with TextField
           width : Ti.UI.FILL,
           height : 50,
           softKeyboardOnFocus : Ti.UI.Android.SOFT_KEYBOARD_SHOW_ON_FOCUS
       });
        
       dirView.add(searchBar);
        
       //the cursor shows up in the search bar but the keyboard never opens
       //searchBar.focus();
        
       //uncommenting these lines 'fixes' the problem
        
       // var thelist = Titanium.UI.createTableView();
       // dirView.add(thelist);
       
       var fireFocus = false;
       win.addEventListener('postlayout', function() {
       if (!fireFocus) {
       	searchBar.focus();
       	fireFocus = true;
       }
       
       });
       win.add(dirView);
       win.open(); 
       
       
       
  3. Ben Zeghers 2012-11-06

    I tested this on master and it seems to be fixed. Thanks
  4. Anshu Mittal 2013-05-09

    Tested with: SDK:3.1.1.v20130508233955 Appcelerator Studio: 3.1.1.201305072102 OS: OSX 10.7.5 Device: LG-p970(2.2.2), Android emulator(2.3.3) works as expected

JSON Source