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
sharanappa
Posts: 29
Registered: ‎11-06-2009
My Device: Not Specified

Not able to Scroll thru the CustomButtons Horizontally.

Hi All,

 

I have created the CustomButtonField which has 3 Bitmap images. Images and selection part works fine. But i am not able to scroll horizontally. but by default it works Vertically. by scrolling the up and down. but left and right is not working.

 

i have arranged 3 buttons Horizontally. and also i have used SCROLL_HORIZONTALLY. but still not getting it work please can you give some tips to fix this issue.

 

 

Thanks & Regards,

Sharan

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Not able to Scroll thru the CustomButtons Horizontally.

I don't have problems with buttons in a HorizontalFieldManager, can you share your code with us?

 

I don't mean all your code, can you reproduce your problem with a standard button in a standard HorizontalFieldManager and post that.

 

If it works using the standard Manager/Field, then slowly incorporate your changes to these until it breaks.  if you can't figure out why it breaks, post the code after it breaks, telling us what you changed and we can have a look at it. 

Please use plain text.
New Developer
sharanappa
Posts: 29
Registered: ‎11-06-2009
My Device: Not Specified

Re: Not able to Scroll thru the CustomButtons Horizontally.

Hi Peter,

 

 

Please find the code here

 

public class CustomButtonField extends Field
{
      //private Bitmap _currentPicture;
      private Bitmap _onPicture;
      private Bitmap _offPicture;
      private Bitmap currentPicture;
      public boolean isFocus = false;
      boolean focused = false;

      public CustomButtonField(String label,int width , int height)
      {           
          //Empty Block
      }
     
      public CustomButtonField(long style,Bitmap offImage , Bitmap onImage){

         super(style);
         _onPicture = onImage;
         _offPicture = offImage;
         currentPicture = _offPicture;
      }

      public int getPreferredHeight(){

          return currentPicture.getHeight();
      }

      public int getPreferredWidth(){

          return currentPicture.getWidth();
      }

      protected void drawFocus(Graphics graphics, boolean on)
      {         
          // Do Nothing         
      }

      protected void onFocus(int direction)
      {
         currentPicture = _onPicture;
         isFocus = true;
         invalidate();
      }
     
      protected void onUnfocus()
      {       
        currentPicture = _offPicture; 
        isFocus = false;
        invalidate();
      }

      protected void layout(int width, int height)
      {
          setExtent(Math.min(width,getPreferredWidth()) , Math.min(height , getPreferredHeight()));
      }

      protected void paint(Graphics graphics)
      { 
          if (isFocus)
          {
              //graphics.setColor(Color.RED);
              graphics.drawBitmap(0,0,getWidth(),getHeight(),currentPicture,0,0);
          }
          else
          {
              graphics.drawBitmap(0,0,getWidth(),getHeight(),currentPicture,0,0); 
          }
      }

      protected  boolean trackwheelClick(int status, int time)
      {
          this.fieldChangeNotify(150);
          return true;
      }
     
}

 

 

 

And here is the code from Action

 

HorizontalFieldManager bottom = new HorizontalFieldManager(Field.FIELD_HCENTER);
         Bitmap bmon = Bitmap.getBitmapResource(HDR_BITMAP_SETTINGS);
         Bitmap bmoff = Bitmap.getBitmapResource(HDR_BITMAP_SETTINGS_OFF);
       
         settingsBitmapField = new CustomButtonField(Field.FOCUSABLE , bmon , bmoff);
       
         //Add listener to the buttons so they can process the action accordingly
         settingsBitmapField.setChangeListener(btn1_click);
         //screen.add(_new);       
         bottom.add(settingsBitmapField);
       
         // Add the Space Here
         bottom.add(new LabelField("  ",Field.NON_FOCUSABLE));
         
         //End
         //HorizontalFieldManager bottom1 = new HorizontalFieldManager();
         Bitmap bmon11 = Bitmap.getBitmapResource(HDR_BITMAP_HELP);
         Bitmap bmon11_off = Bitmap.getBitmapResource(HDR_BITMAP_HELP_OFF);
   
         helpBitmapField = new CustomButtonField(Field.FOCUSABLE , bmon11 , bmon11_off);
         //screen.add(_new1);
         //Add listener to the buttons so they can process the action accordingly
         helpBitmapField.setChangeListener(btn1_click);
         bottom.add(helpBitmapField);
         bottom.add(new LabelField("  ",Field.NON_FOCUSABLE));
       
         Bitmap about = Bitmap.getBitmapResource(HDR_BITMAP_ABOUT);
         Bitmap about_off = Bitmap.getBitmapResource(HDR_BITMAP_ABOUT_OFF);
   
         aboutBitmapField = new CustomButtonField(Field.FOCUSABLE , about , about_off);
         //screen.add(_new1);
       
         aboutBitmapField.setChangeListener(btn1_click);
         bottom.add(aboutBitmapField);   
       
         screen.add(bottom);

 

 

But this is scrolling only vertically but not horizontally

 

 

 

Thanks

Sharan

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Not able to Scroll thru the CustomButtons Horizontally.

Sorry, I don't have time to look at this now, and I suspect you do some more debugging yourself.  Did you read all of my previous post?  Here is the part I'm not sure you have read:

 

"I don't mean all your code, can you reproduce your problem with a standard button in a standard HorizontalFieldManager and post that.

 

If it works using the standard Manager/Field, then slowly incorporate your changes to these until it breaks.  if you can't figure out why it breaks, post the code after it breaks, telling us what you changed and we can have a look at it."

 

So work through this and let us know how you get on.

Please use plain text.