06-10-2011 09:37 AM
I would like to generate a button click event. But unlike the examples I found in the forum, I do not simply want to replace a key-press with a button click. I want the button to be (auto-clicked) clicked if a certain logical condition is met.
Anyone know how to generate an event like that ?
06-10-2011 09:43 AM
06-10-2011 09:55 AM
Do you have a sample ?
I would want to evaluate a value during the building of a user screen - if I notice that something is incorrect I want to "submit" the form immediately - and regenerate it.
eg.
public final class connect extends UiApplication implements FieldChangeListener
{
String log_tx;
ButtonField okbut;
LabelField tx;
boolean something_not_yet_ready;
/**
*
*/
MainScreen screen;
/**
* Entry point for the application
*
* @param args Command line arguments (not used)
*/
public static void main(String[] args)
{
connect sample = new connect();
// Make the currently running thread the application's event
// dispatch thread and begin processing events.
sample.enterEventDispatcher();
}
void show_start_screen(){
if(screen!=null){
popScreen(screen);
}
screen = new MainScreen();
screen.setTitle("Connection checker BlackBerry");
okbut = new ButtonField("Clear", Field.FIELD_HCENTER |ButtonField.NEVER_DIRTY | ButtonField.CONSUME_CLICK);
okbut.setChangeListener(this);
screen.add(okbut);
if(something_not_yet_ready==true){
// generate event ! as if button was clicked.
}
pushscreen(screen);
}
}
public void fieldChanged(Field field, int context)
{
try
{
if(field.equals(okbut))
{
something_not_yet_ready=false;
}
}
06-10-2011 10:08 AM
06-10-2011 10:23 AM
The reason is that I am using the BrowserField.
It never returns the actual html code (that I am after) correctly after the first call; However, I have found that if I invoke it twice it somehow starts working (and correctly calls the listener event). Therefore if I can simulate the repeated button pressing - I should be able to get the listener activated automatically. I can paste that code (but I was worried it may just confuse the topic under discussion).
06-10-2011 10:27 AM
06-10-2011 11:55 AM
Simon, great idea. I tried it, but I suspect because I don't actually display the BrowserField (I just use it as a reliable connection to the http) - the invalidate has no effect. The Field's listener therefore does not run again - I have tried doing an invalidate on the mainscreen itself - even this.updateDisplay - but the listener is simply not run again.
06-14-2011 06:39 AM
I have now found that the browserField listener remains one step behind the actual displayed text (despite doing invalidates and even forcing the mainscreen to re-generate)
It always returns the "Previously" displayed content.
My need therefor remains to be able to generate a button click - Instead of asking my user to click it twice .
Please help !