08-17-2010 10:35 AM
hi all,
I want to clear all the editFields on pressing the escape key. I know that i have to implement a keyListener but what i don't know what to add to clear the editFields.
If anybody knows how to do this please share.
Thanks
Solved! Go to Solution.
08-17-2010 10:46 AM
Field curField = UiApplication.getUiApplication.getActiveScreen().getLeafFieldWithFocus(); if ((curField != null) && (curField instanceof EditField)) { ((EditField)curField).setText(""); curField.invalidate(); }
08-18-2010 06:21 AM
I want to clear all the editFields of the previous screen on pressing the escape key. i think this might clear only the fields with focus(of the current screen).
08-18-2010 07:04 AM
Just go through each field and if it is EditField setText to "".
getScreenBelow(), getFieldCount(), getField() and instanceof are your friends.
08-18-2010 12:03 PM
since i m implementing this in a keylistener class, which will be adde to almost all screens, so this doesn't seem to work out
08-18-2010 12:11 PM
Then add UiApplication.getUiApplication().getActiveScreen() to the picture. I guess you want to pop that screen and "clean" the previous screen (which is about to show up) before doing so.
Something like that:
Screen activeScr = UiApplication.getUiApplication().getActiveScreen(); Screen nextScreen = null; if (activeScr != null) { nextScreen = activeScr.getScreenBelow(); } if (nextScreen != null) { int count = nextScreen.getFieldCount(); for (int i = count - 1; i >= 0; --i) { Field curField = nextScreen.getField(i); if (curField instanceof TextField) { ((TextField) curField).setText(""); } } }
08-19-2010 03:18 AM
i solved the problem. i am poping the below screen, creating a new instance of that particular screen and pushing it using invokeLater
public class KeyListenerImplementation implements KeyListener
{
private Screen belowScreen;
public boolean keyChar( char key, int status, int time )
{
if ( key == Characters.ESCAPE && UiApplication.getUiApplication().getScreenCount()>
{
belowScreen = UiApplication.getUiApplication().getActiveScreen()
if(belowScreen instanceof XXScreen){
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run() {
UiApplication.getUiApplication().popScreen(belowS
UiApplication.getUiApplication().pushScreen(new XXScreen));
}
});
}
}}