开发者

How to change the picture of CustomButtonField on click event?

开发者 https://www.devze.com 2023-03-16 08:03 出处:网络
I have posted this question previously but the answer is not appropiate. The solution provided just change the picture when the custombutton has focus and unfocus. Suppose in my application I need to

I have posted this question previously but the answer is not appropiate. The solution provided just change the picture when the custombutton has focus and unfocus. Suppose in my application I need to change the picture if the user clicks on the customButton, n i m doing this by calling the same screen (ie UiApplication.getUiApplication().pushScreen(new Screen2(b));) . Screen2 is the screen which holds the customButton. 开发者_JS百科On the click evevt i m pushing the same screen by passing aint variable pic_status that determines which picture to be drawn in the CustomButton in the new screen. Is there any way to update the picture in the CustomButtonField on click event without pushing the same Screen again and again.

 //code in Screen2

public void fieldChanged(Field field, int context) 
 {
    if(field == bf1)
     {

         if(pic_status == 0)
         {
             pic_status=1;


         }
       UiApplication.getUiApplication().pushScreen(new Screen2(pic_status));    


  }



 //code in CustomButtonField

CustomButtonField(String label,int pic_status,long style) 
{    
    super(style);
    this.label = label;
    this.labelHeight = getFont().getHeight();
    this.labelWidth = getFont().getAdvance(label);
    this.notice = s;
    if(pic_status ==0)
    {
    currentPicture1 = onPicture;
    currentPicture2 = onPicture;
    }
    if(pic_status ==1)
    {
    currentPicture1 = clickPicture;
    currentPicture2 = onPicture;
    }
    if( pic_status==2 )
    {
        currentPicture1 = onPicture;
        currentPicture2 = clickPicture;
    }
}

I need a way to update the customButtonField text and picture on the buttonClick event not on focus/unfocus event without pushing the same Screen again and again. If my above description of problem is not satisfactory, plz add a comment n i can give more details explanation of my problem?


We can override some methods of the CustomButtonField such as protected boolean keyChar(...), protected boolean navigationClick(...), protected boolean trackwheelClick(...), protected boolean touchEvent(...), etc and use them to change button image when click or select event occurred.

For example on protected boolean touchEvent(...) we can do following task..

  1. Replace the image with desired ones when we get TouchEvent.ClICK.
  2. Call invalidate().
  3. On TouchEvent.UNCLICK restore original image.
  4. Call invalidate().
0

精彩评论

暂无评论...
验证码 换一张
取 消