0

enter image description here

I am creating a map app. in which i am using mapfield. on the MapFieldScreen I am trying to add Title and also creating tabs but these two things are not visible. instead there is just gray color on these two places..

Here is my code.

class MapFieldScreen extends MainScreen
{ 
MapFieldScreen()
{   
    title= new LabelField("My Trip",LabelField.FIELD_HCENTER|LabelField.USE_ALL_WIDTH)
    {
       protected void layout(int width,int height)
       {
            setExtent(UIConstants.SCREEN_WIDTH, getFont().getHeight()*2);
       }
       public void paint(Graphics g)
        { 
            g.setColor(Color.WHITE);             
            g.drawText(label,UIConstants.SCREEN_WIDTH*2/5,getFont().getHeight()/2);  
            super.paint(g); 
        }
    };
    setTitle(title);    
    mLoc= Bitmap.getBitmapResource(UIConstants.STOP);
    mmMapField = new MapField();

    add(mMapField);

}
}
Swati
  • 1,179
  • 9
  • 28
  • There is no tab in above sample code, only title and map. – Rupak Jan 11 '12 at 05:36
  • ya.. actually i am extending the tab class. even that titlebar is also not comming. – Swati Jan 11 '12 at 06:01
  • I have pasted this code in one of my `MainScreen`, and the title is working (though I'm not sure why you call `super.paint()` if you are doing the paint by yourself). And I got gray color on map. – Rupak Jan 11 '12 at 06:13
  • Actually this super.paint is for some gradient effect which I want. I am creating that gardient effect also.. for this code its not required. – Swati Jan 11 '12 at 06:51
  • did you test the version, setTitle("String")? – Rupak Jan 11 '12 at 07:11

1 Answers1

0

You can check follwing code:

LabelField title = new LabelField("My Trip") {
    int _width = Display.getWidth();
    int _height = getFont().getHeight() * 2;

    protected void layout(int width, int height) {
        setExtent(_width, _height);
    }

    public void paint(Graphics graphics) {
        graphics.setColor(Color.WHITE);
        int xText = (_width - getFont().getAdvance(getText())) / 2;
        int yText = (_height - getFont().getHeight()) / 2;
        graphics.drawText(getText(), xText, yText);
    }
};

setTitle(title);
Rupak
  • 3,674
  • 15
  • 23
  • without mapfield my code is working f9. i am using this same code with other screen but its not working for the mapfields. – Swati Jan 11 '12 at 07:09