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
New Developer
Posts: 17
Registered: ‎05-15-2009
My Device: Not Specified
Accepted Solution

2 buttons with navigation click change the status of the other button when click

[ Edited ]

Hi to everybody!!

 

i have a big problem with one of my applications.

 

I have two buttons in the app when push one of the buttons i want to change the bitmap of the other button i will show the code if someone can help me i would greatly appreciate it ;D

 

 

BitmapField Libre = new BitmapField(icono_libre, BitmapField.FOCUSABLE | BitmapField.HCENTER ) {
protected boolean navigationClick(int status, int time) {
if(estado.getEstado()== true){
setBitmap(icono_libre);
estado.setEstado(false);
}
else{
setBitmap(iconoBlanco);
estado.setEstado(false);
}

return true;
}
public void onUnfocus()
{
super.onUnfocus();
if(estado.getEstado()==true){
setBitmap(iconoBlanco);
}else{
setBitmap(icono_libre);

}

}
protected void drawFocus(Graphics _g, boolean _on) {}
};

 

 

BitmapField Ocupado = new BitmapField(iconoBlanco, BitmapField.FOCUSABLE

| BitmapField.HCENTER ) {
protected boolean navigationClick(int status, int time) {
if(estado.getEstado()== false){
setBitmap(icono_ocupado);
estado.setEstado(true);
// Libre.setBitmap(icono_libre);
}
else{
estado.setEstado(true);
setBitmap(iconoBlanco);
}

return true;
}
public void onUnfocus()
{
super.onUnfocus();
if(estado.getEstado()==false){
setBitmap(iconoBlanco);
}else{
setBitmap(icono_ocupado);
}
}
protected void drawFocus(Graphics _g, boolean _on) {}
};

 i want when click on the button for example

// Libre.setBitmap(icono_libre);

 but it's not works because i can't enter on the other bitmapfield.

 

Im waiting your answer thanks in advance ;E

 

Message Edited by boogeyman on 05-27-2009 04:31 PM
Message Edited by boogeyman on 05-27-2009 04:33 PM
Message Edited by boogeyman on 05-27-2009 04:34 PM
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: 2 buttons with navigation click change the status of the other button when click

I have a suggestion.  Instead of overriding navigationClick on the Field, do it at the Screen level.  Then you can use

 

Field focus = this.getLeafWithFocus();

if ( focus == Libre ) {

...

} else

if ( focus == Ocupado ) {

.... 

{

 

However I'm wondering if you aren't making life hard for yourself.  Why not have one BitmapField, with Libre and Ocupado bitmaps, and use the click to change bitmap between Libre and Ocupado.

New Developer
Posts: 17
Registered: ‎05-15-2009
My Device: Not Specified

Re: 2 buttons with navigation click change the status of the other button when click

thanks for your help it maybe be the solution i will try it,but im going to explain it better:

 

i need two buttons(bitmapfields) on the screen at the same time when 1 it's Libre(free) it have a green icon and the other Ocupado(busy) its white, when press on the Ocupado button i want to change the colour of the Libre button to white and change the colour of the Ocupado button to red. the first bitmapfield only can change two colours green and white and the other button red and white.

 

please tell me a solution Smiley Very Happy

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

Re: 2 buttons with navigation click change the status of the other button when click

peter suggested a possible solution. control the buttons at screen level.
if you want the control on button level you need a control class. take a look at the RadioButton and RadioButtonGroup classes, it is the same approach. basically it is a callback that is called on all other 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
New Developer
Posts: 17
Registered: ‎05-15-2009
My Device: Not Specified

Re: 2 buttons with navigation click change the status of the other button when click

[ Edited ]
uhmmm radiobutton don't work because i need a specific bitmap on the fields and the change must occur when press the button instead of when focus.. >_<
Message Edited by boogeyman on 05-28-2009 02:38 PM
Developer
Posts: 16,984
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: 2 buttons with navigation click change the status of the other button when click

i was comparing the radiobuttongroup system to the one you could use
----------------------------------------------------------
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
New Developer
Posts: 17
Registered: ‎05-15-2009
My Device: Not Specified

Re: 2 buttons with navigation click change the status of the other button when click

[ Edited ]

I can't make it work, if someone could help me and show me an example ..I would really appreciate that Smiley Happy

 

 

Message Edited by boogeyman on 05-28-2009 04:29 PM
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: 2 buttons with navigation click change the status of the other button when click

Can you explain what you want to do exactly? A bit clearly, I don't understand it..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
New Developer
Posts: 17
Registered: ‎05-15-2009
My Device: Not Specified

Re: 2 buttons with navigation click change the status of the other button when click

Ok.

 

http://s3.subirimagenes.com/otros/previo/thump_2622611ejemo.jpg

 

2 bitmapfield: green button and red button, by default the bitmap of the green button are green and the red button white.

 

i want,when press the red  button the red button changes the colour to red and the green button to white.

 

http://s3.subirimagenes.com/otros/previo/thump_2622639ejemo2.jpg

 

and when press the green button,if the red button are activated change another time but if the red button aren't activated don't happen nothing

 

two status with a boolean false = green activated,true = red activated.

 

please i need help T_T

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

Re: 2 buttons with navigation click change the status of the other button when click

take three bitmaps: white, red and green.
take a boolan variable for the status: active
on navigationclick determine the field with focus (getLeafFieldWithFocus()).
if one of your buttons is clicked change the status variable: active = !active
depending on the status call setBitmap with the correct bitmap on each button.

this would be peters suggestion. as long as you have only two buttons it is the easiest way,
----------------------------------------------------------
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