Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 24
Registered: ‎06-03-2011
My Device: Curve
My Carrier: Vodacom SA

generating a button click

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 ?

 

Developer
Posts: 16,750
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: generating a button click

you can use event injector. but depending on your usecase it creates more problems then solving, so be careful.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 24
Registered: ‎06-03-2011
My Device: Curve
My Carrier: Vodacom SA

Re: generating a button click

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;         

            }
 }

 

Developer
Posts: 16,750
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: generating a button click

i don't see why you cannot invoke whatever command you need directly.
event injection is only needed when interacting with an UI you have no control over.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 24
Registered: ‎06-03-2011
My Device: Curve
My Carrier: Vodacom SA

Re: generating a button click

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).

 

Developer
Posts: 16,750
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: generating a button click

and calling invalidate on the browserfield does not work?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 24
Registered: ‎06-03-2011
My Device: Curve
My Carrier: Vodacom SA

Re: generating a button click

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.

 

 

 

Contributor
Posts: 24
Registered: ‎06-03-2011
My Device: Curve
My Carrier: Vodacom SA

Re: generating a button click

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 !