Sencha Touch Hide Pickers on Android Back Key Press

Hello,

I recently published an article about hiding sencha touch Message box on press of back button in android. You can read it here Sencha Touch Hide Alert Box on Android Back Button Press

This post is something similar to it. Recently we created an android application with Sencha Touch and Cordova for client. After testing, client came up with requirement that if any picker is open for example calendar picker or select field picker etc. It should be closed on press of back button in android. So after efforts of half an hour, I found a solution. 
In Sencha Touch pickers are basically floating panels. So what we have to do it get all the floating panels and see if it’s hidden or not. If not hidden then hide it.
First of all you have to bind back button event of android using cordova. Please check this cordova document on how to do this here.
Once you add backbutton listener, add following code.
var floatingComponents = Ext.query(‘.x-floating’);
for(var i=0;i

var component = Ext.getCmp(floatingComponents[i].id);
if(component){
if(component.isHidden() == false){
component.hide();
return;
}
}
}

As you can see in above code, first we are finding all the floating component using Ext.query and class x-flaoting
Then we loop through it and find component using id of floating component and check if component is not hidden then hide it and return from there. 
Hope this helps you.
This entry was posted in Cordova, Mobile, Mobile Application, Sencha, Sencha Touch, Sencha Touch 2 on by .

About Hiren Dave

Hiren Dave is a software engineer, blogger and consultant with over 9 years of professional experience. He writes code in number of languages. Hiren has a passion for developing web apps, mobile apps and writing books and blog articles about programming. He has a solid experience of startups as he manages products for few startups. He is also passionate about researching and learning new technologies and trends. He has also authored a book Instant Sencha Touch, published by Packt and creator of Video Course "Beginning Laravel" for Packt

Leave a Reply

Your email address will not be published. Required fields are marked *