I want to display a map with some coordinates, I can do it on one GUI Element, but when I duplicate the code for other GUI Element the map doesn't appear
This is the code for one GUI Element (page or screen)
@Override
protected void beforeMapaGPS(Form f) {
MapComponent mapComponent= new MapComponent();
double latitude=-41.169782;
double longitude =-71.444885;
Coord lastLocation = new Coord(latitude, longitude);
mapComponent.zoomTo(lastLocation, 15);
f.setLayout(new FlowLayout());
f.addComponent(mapComponent);
f.show();
}
and this is the other GUI Element (other page or screen) is copied from the first
@Override
protected void onCreateGUI1() {
MapComponent mapComponent= new MapComponent();
double latitude=-41.169782;
double longitude =-71.444885;
Coord lastLocation = new Coord(latitude, longitude);
mapComponent.zoomTo(lastLocation, 15);
f.setLayout(new FlowLayout());
f.addComponent(mapComponent);
f.show();
}
when I run the simulator the map appear on the first page or screen, and not on the other
Message received when I save the designer
答案 0 :(得分:2)
首先,不要将FlowLayout用于任何对等组件或复杂组件,如Map,Browser,List,Multi-list ......
其次,您正在onCreate
方法中为第二个表单实现Map代码。在beforeShow()
或postShow()
方法中进行。
最后,您通过在f.show()
方法中调用beforeShow()
来请求已经显示的表单。
将您的代码更改为:
@Override
protected void beforeMapaGPS(Form f) {
MapComponent mapComponent= new MapComponent();
double latitude=-41.169782;
double longitude =-71.444885;
Coord lastLocation = new Coord(latitude, longitude);
mapComponent.zoomTo(lastLocation, 15);
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, mapComponent);
}
和第二个:
@Override
protected void beforeGUI1(Form f) {
MapComponent mapComponent= new MapComponent();
double latitude=-41.169782;
double longitude =-71.444885;
Coord lastLocation = new Coord(latitude, longitude);
mapComponent.zoomTo(lastLocation, 15);
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, mapComponent);
}