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
Regular Contributor
pankaj_pradeep
Posts: 88
Registered: ‎04-09-2010
My Device: 9530
My Carrier: Software Developer

ButtonField click event

Hi all i am not implementing touch event. i am using FieldChangeListener the problem which i am facing is , if i am clicking outside the CustomButtonField then also the click event is generated how should i restrict only to the CustomButtonField. Thanks alot
Please use plain text.
Contributor
SirSaula
Posts: 30
Registered: ‎04-13-2010
My Device: N/A
My Carrier: T-Mobile

Re: ButtonField click event

A way I define my FieldChangeListeners is as so. Hope this is of help and I understood your question properly. This way When i click anywhere else the program does not execute UNLESS that specific button is clicked or pushed.

 

 

//Create your button
ButtonField Truth = new ButtonField("Truth",ButtonField.CONSUME_CLICK);

//Create the listener
FieldChangeListener customListener = new FieldChangeListener() {   
              public void fieldChanged(Field field, int context) {    
            	 

             }   
              };   

//Set the button to that specific listener
Truth.setChangeListener(customListener); 

 

 

Thanks,
Saula
Your neighborhood programmer.
http://homeworkjava.com
Please use plain text.
Regular Contributor
pankaj_pradeep
Posts: 88
Registered: ‎04-09-2010
My Device: 9530
My Carrier: Software Developer

Re: ButtonField click event

I am already using field changed method and checking each CustomButton. The problem is if , i am clicking anywhere on the screen the button which is onfocous is getting selected
Please use plain text.
Developer
rakesh86shankar
Posts: 988
Registered: ‎05-22-2009
My Device: Not Specified

Re: ButtonField click event

Just give ur code.i may help you.this is sample code,it will help you

 

 

public class testform extends MainScreen implements FieldChangeListener
{
    Button b,b1;
    ButtonField b2;
    testform()
    {
        this.add(new LabelField("testform"));
        
        
       b2=new ButtonField("ADd");
       b2.setChangeListener(this);
       
                
        /*b=new Button(Bitmap.getBitmapResource("details-passive.png"),Bitmap.getBitmapResource("details.png"),Field.FIELD_HCENTER);
        b.setChangeListener(this);
        this.add(b);
        
      
        b1=new Button("Login",Field.FIELD_HCENTER);
        b1.movePos(5,0,0,0);
        
        b1.setChangeListener(this);
        this.add(b1);
        this.add(new ButtonField("Login",ButtonField.FIELD_HCENTER));*/
       
        
         
    }

    public void fieldChanged(Field arg0, int arg1) 
    {
        if(arg0.equals(b1))
        {
          this.add(new LabelField("b1"));
        }
        else if(arg0.equals(b))
        {
            this.add(new LabelField("log Button clicked"));
        }
        if(arg0.equals(b2))
        {
            this.add(new LabelField("Default Button clicked"));
        }
    }

 Try with this code.Remove the button ,replace with ButtonField,i have added one

 

 

 

Regards

Rakesh Shankar.P

 

Please use plain text.
Regular Contributor
pankaj_pradeep
Posts: 88
Registered: ‎04-09-2010
My Device: 9530
My Carrier: Software Developer

Re: ButtonField click event

Thanks Rakesh for the response , i think u din't get me . my question is i have created a CustomButtonField and i am using that CustomButtonField in a Screen. if that CustomButtonField is onFocous and i am clicking on screen (not on CustomButtonField) then also that button is firing event.

Please use plain text.
New Contributor
sudhanshu_sri
Posts: 5
Registered: ‎04-02-2012
My Device: 9900
My Carrier: m

Re: ButtonField click event

i think your screen is also focusable. remove that . and set your button as consume click.

Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: ButtonField click event

a code snippet or some implementation details would be helpful here.

 

my first guess would be that you have implemented fieldchangelistener in the screen and added it to several fields. 

----------------------------------------------------------
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
Please use plain text.