LWUIT List not scrolling - list

I have inserted a list in my j2ME project,designed using LWUIT. The code is as follows
Button btnHome;
Button btnExit;
List list;
setScrollableY(false);
setScrollable(false);
list = new List();
MyRenderer render = new MyRenderer();
list.setListCellRenderer(render);
list.getStyle().setFgColor(0xfaedf2);
list.setSmoothScrolling(true);
list.addSelectionListener(new SelectionListener(){
public void selectionChanged(int i, int i1) {
try {
InformationForm form = new InformationForm();
form.show();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
String[] arrString = builder.getArrName();
System.out.println(arrString.length);
for (int i = 0; i < arrString.length ; i++)
{
list.addItem(arrString[i]);
// System.out.println("item no " + i +" = " +arrString[i] + "added in list");
}
BorderLayout bl=new BorderLayout();
setLayout(bl);
Container holdingContainer=new Container(new FlowLayout(Component.LEFT));
Container c0 = new Container(new BoxLayout(BoxLayout.X_AXIS));
Container c1 = new Container(new FlowLayout(Component.LEFT));
Container c2 = new Container(new FlowLayout(Component.LEFT));
Container footerContainer=new Container(new BoxLayout(BoxLayout.X_AXIS));
c0.addComponent(cityChoice);
c0.addComponent(btnFilter);
//c2.addComponent(list);
c1.setPreferredH(25);
holdingContainer.addComponent(c0);
holdingContainer.addComponent(c1);
getStyle().setBgColor(0x730E36);
// holdingContainer.addComponent(c2);
holdingContainer.setPreferredH(280);
holdingContainer.setScrollableY(true);
addComponent(BorderLayout.CENTER,list);
//addComponent(BorderLayout.WEST,holdingContainer);
footerContainer.getStyle().setMargin(Component.LEFT, 0);
footerContainer.addComponent(btnHome);
footerContainer.addComponent(btnExit);
addComponent(BorderLayout.SOUTH,footerContainer);
The renderer for list is,
public class MyRenderer extends TextArea implements ListCellRenderer{
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected){
getStyle().setBorder(Border.createEmpty());
getStyle().setFgColor(0xfaedf2);
getStyle().setBgColor(isSelected ? 0x630A2E : 0x730E36);
setText(value.toString());
if (isSelected) {
setFocus(true);
getStyle().setBgTransparency(100);
} else {
setFocus(false);
getStyle().setBgTransparency(0);
}
return this;
}
public Component getListFocusComponent(List list){
return null;}
}
The problem is when on device, i try to scroll the list, the item on which i touched is selected immediatly and the new form for it is opened. I do not able to scroll the list at all. Please help me in solving this problem.

Is it possible you are using a SelectionListener instead of an ActionListener?

Related

UWP C++ PrintTask PreviewPage Duplication Error

I'm currently working on a print task within my app to print a couple of pages to either printer or PDF. I'm using the microsoft printsample as the basis for my code and it all works with the exception of one thing. When I change printers, the printer preview creates duplicate pages of the content I sent to the printer preview.
Here is all my code that handles the printing. Does anyone know what might be causing the print UI to create duplicate preview pages when changing between printers and or print to PDF? thanks.
void MainPage::Print_Test_Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
if (isPrinting) {
pDocument->InvalidatePreview();
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
printMan->PrintTaskRequested -= printTaskRequestedEventToken;
isPrinting = false;
}
this->Certificate_SV_1->ScrollToVerticalOffset(0.0);
this->Certificate_SV_2->ScrollToVerticalOffset(0.0);
// CREATE THE PRINT DOCUMENT
pDocument = ref new Windows::UI::Xaml::Printing::PrintDocument();
// SAVE DOCUMENT SOURCE
pDocumentSource = pDocument->DocumentSource;
// CLEAR CACHE OF PREVIEW PAGES
printPreviewPages.clear();
// Add an event handler which creates preview pages.
pDocument->Paginate += ref new Windows::UI::Xaml::Printing::PaginateEventHandler(this, &MainPage::CreatePrintPreviewPages);
// Add an event handler which provides a specified preview page.
pDocument->GetPreviewPage += ref new Windows::UI::Xaml::Printing::GetPreviewPageEventHandler(this, &MainPage::GetPrintPreviewPage);
// Add an event handler which provides all final print pages.
pDocument->AddPages += ref new Windows::UI::Xaml::Printing::AddPagesEventHandler(this, &MainPage::AddPrintPages);
// PRINT MANAGER
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
// RAISE NEW PRINT TASK REQUEST
printTaskRequestedEventToken = printMan->PrintTaskRequested += ref new Windows::Foundation::TypedEventHandler<Windows::Graphics::Printing::PrintManager^, Windows::Graphics::Printing::PrintTaskRequestedEventArgs^>(this, &MainPage::PrintTaskRequested);
// SHOWS THE PRINTER UI
printMan->ShowPrintUIAsync();
}
.
void MainPage::CreatePrintPreviewPages(Object^ sender, Windows::UI::Xaml::Printing::PaginateEventArgs^ e)
{
Windows::UI::Xaml::Printing::PrintDocument^ printDocument = safe_cast<Windows::UI::Xaml::Printing::PrintDocument^>(sender);
hasOverFlow = false;
StackPanel^ PrinterPage = ref new StackPanel();
PrinterPage->Width = 794; PrinterPage->Height = 1123;
PrinterPage = safe_cast<StackPanel^>(this->Certificate_Page_1);
// ADD PAGE TO THE COLLECTION
printPreviewPages.push_back(PrinterPage);
PrinterPage = safe_cast<StackPanel^>(this->Certificate_Page_2);
printPreviewPages.push_back(PrinterPage);
// Report the number of preview pages created
printDocument->SetPreviewPageCount(printPreviewPages.size(), Windows::UI::Xaml::Printing::PreviewPageCountType::Final);
}
.
void MainPage::GetPrintPreviewPage(Object^ sender, Windows::UI::Xaml::Printing::GetPreviewPageEventArgs^ e)
{
Windows::UI::Xaml::Printing::PrintDocument^ localprintDocument = safe_cast<Windows::UI::Xaml::Printing::PrintDocument^>(sender);
localprintDocument->SetPreviewPage(e->PageNumber, printPreviewPages[e->PageNumber - 1]);
}
.
void MainPage::AddPrintPages(Object^ sender, Windows::UI::Xaml::Printing::AddPagesEventArgs^ e)
{
Windows::UI::Xaml::Printing::PrintDocument^ printDocument = safe_cast<Windows::UI::Xaml::Printing::PrintDocument^>(sender);
for (uint8_t i = 0; i < printPreviewPages.size(); i++) {
printDocument->AddPage(printPreviewPages[i]);
}
// Indicate that all of the print pages have been provided
printDocument->AddPagesComplete();
}
.
void MainPage::PrintTaskRequested(Windows::Graphics::Printing::PrintManager^ sender, Windows::Graphics::Printing::PrintTaskRequestedEventArgs^ e) {
Windows::Graphics::Printing::PrintTask^ printTask = e->Request->CreatePrintTask("PRINT TASK", ref new Windows::Graphics::Printing::PrintTaskSourceRequestedHandler([=](Windows::Graphics::Printing::PrintTaskSourceRequestedArgs^ args)
{
args->SetSource(pDocumentSource);
}));
// Print Task event handler is invoked when the print job is completed.
printTask->Completed += ref new Windows::Foundation::TypedEventHandler<Windows::Graphics::Printing::PrintTask^, Windows::Graphics::Printing::PrintTaskCompletedEventArgs^>([=](Windows::Graphics::Printing::PrintTask^ sender, Windows::Graphics::Printing::PrintTaskCompletedEventArgs^ e)
{
// Notify the user when the print operation fails.
if (e->Completion == Windows::Graphics::Printing::PrintTaskCompletion::Failed)
{
auto callback = ref new Windows::UI::Core::DispatchedHandler([=]()
{
this->DataStreamWindow->Text = "Printing Failed!";
pDocument->InvalidatePreview();
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
printMan->PrintTaskRequested -= printTaskRequestedEventToken;
isPrinting = false;
});
Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, callback);
}
else if (e->Completion == Windows::Graphics::Printing::PrintTaskCompletion::Canceled)
{
auto callback = ref new Windows::UI::Core::DispatchedHandler([=]()
{
this->DataStreamWindow->Text = "Printing Cancelled!";
pDocument->InvalidatePreview();
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
printMan->PrintTaskRequested -= printTaskRequestedEventToken;
isPrinting = false;
});
Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, callback);
}
pDocument->InvalidatePreview();
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
printMan->PrintTaskRequested -= printTaskRequestedEventToken;
isPrinting = false;
});
}

Accessing retrofit 2 data outside on response?

I am working on two apps, in one of my app "A" i applied retrofit 2.
This was the method i used to retrieve data.
But here in on Response the data retrieved in response body can be set to activity variables and can be used outside this method without getting null values.
public void fetch_information() {
ApiInterface = ApiClient.getApiClient().create(Api.class);
Call<List<City>> call = ApiInterface.GetCities();
call.enqueue(new Callback<List<City>>() {
#Override
public void onResponse(Call<List<City>> call, Response<List<City>> response) {
citylist = new ArrayList<City>();
citylist = response.body();
cities = new String[citylist.size()];
citiesid = new String[citylist.size()];
for (int i = 0; i < citylist.size(); i++) {
cities[i] = citylist.get(i).getCityName();
citiesid[i] = citylist.get(i).getCityId();
}
city_adapter = new ArrayAdapter<String>(Pay_Payment_X.this, android.R.layout.simple_list_item_1, cities);
city_adapter.setDropDownViewResource(R.layout.spinner_dropdown_layout);
City_Spinner.setAdapter(city_adapter);
}
#Override
public void onFailure(Call<List<City>> call, Throwable t) {
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
after applying this method and on debugging this method i will retain values of varaibles "cities" and "citiesid"out side onResponse.
But applying retrofit 2 similarly on another app "B", i did the same thing for retrieving data on different URL.
ApiUtil.getServiceClass().getAllPost().enqueue(new Callback<List<ApiObject>>() {
#Override
public void onResponse(Call<List<ApiObject>> call, Response<List<ApiObject>> response) {
if (response.isSuccessful()) {
List<ApiObject> postList = response.body();
try {
for (int i = 0; i < postList.size(); i++) {
String Name = postList.get(i).getGamesName();
mGamesName.add(Name);
}
} catch (Exception e) {
}
Log.d(TAG, "Returned count " + postList.size());
NewAdapter adapter = new NewAdapter(getApplicationContext(), postList);
recyclerView.setAdapter(adapter);
}
}
#Override
public void onFailure(Call<List<ApiObject>> call, Throwable t) {
//showErrorMessage();
Log.d(TAG, "error loading from API");
}
});
the data is retrievable inside onResponse but outside it shows null.
So here variables are not retaining values.
Why is this happening?
the only thing came to mind is retrieving data can take time while your code lines are being read and finding null values as data has not been received yet.
Also to mention in app "A" the data retrieved is huge but in app "B" only 3 objects with string values.But still in app"A" data is retrievable.
In app 2 did this for resolving my issue.
public void doRequest( final ApiCallback callback){
ApiUtil.getServiceClass().getAllPost().enqueue(new Callback<List<ApiObject>>() {
#Override
public void onResponse(Call<List<ApiObject>> call, Response<List<ApiObject>> response) {
if (response.isSuccessful()) {
List<ApiObject> postList = response.body();
callback.onSuccess(postList);
// apobject =response.body();
if(response.isSuccessful()) {
try {
for (int i = 0; i < postList.size(); i++) {
String Name = postList.get(i).getGamesName().toString();
mGamesName.add(Name);
}
} catch (Exception e) {
}
}
Log.d(TAG, "Returned count " + postList.size());
NewAdapter adapter = new NewAdapter(getApplicationContext(), postList);
recyclerView.setAdapter(adapter);
}
}
#Override
public void onFailure(Call<List<ApiObject>> call, Throwable t) {
//showErrorMessage();
Log.d(TAG, "error loading from API");
}
});
}
pass an interface
public interface ApiCallback{
void onSuccess(List<ApiObject> result);
}
and in on Create view of activity i called this
doRequest(new ApiCallback(){
#Override
public void onSuccess(List<ApiObject> result){
//here i can set variable values
}
});
the only thing came to mind is retrieving data can take time while your code lines are being read and finding null values as data has not been received yet.
That's entirely correct. Your call is finishing after you check the values. I'm going to go on a limb here and say that it's just a coincidence that it works on one app and not in the other (if they are actually doing it the same way)
When you call callback.onSuccess(postList); doesn't seem to be right either, because you haven't checked yet for success. This means that response.body() might be null and response.errorBody() will contain the body of the error.
If you'd move callback.onSuccess inside the if this would be fixed:
if(response.isSuccessful()) {
callback.onSuccess(response.body());
try {
for (int i = 0; i < postList.size(); i++) {
String Name = postList.get(i).getGamesName().toString();
mGamesName.add(Name);
}
} catch (Exception e) {
}
Last but not least, inside the onSuccess method is when you can use your global variables. Maybe it's better to stop using global variables and just use the callback parameters.

LEVENSHTEIN_DISTANCE doesn't ignore order by comparing of lists

P.P.S. Ok, I founded hier Javers Comparing Lists following comment
There is no concept of move in JaVers list comparison algorithms. After a move there will be two changes reported: ValueAdded and ValueRemoved, just like you have mentioned.
But how then I can recognize, that the list actually has not been changed?
P.S. Even if I get #Entities and #Id to ZasFish, ZasCatchZone and ZasCatchArea I still get
Diff:
1. NewObject{globalId:'my.javers.comparator.ZasFish/2'}
2. ObjectRemoved{globalId:'my.javers.comparator.ZasFish/1'}
I'm trying to compare lists of custom objects. I set LEVENSHTEIN_DISTANCE and created custom comparators. The only difference between objects is the order of values in the lists. I would expect "no changes", but I got ListChange. The result and example is below. What am I doing wrong?
Many thanks and regards,
Andrej
Diff:
1. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'zones', containerChanges:[(2).'my.javers.comparator.ZasCatchZone#7a9273a8'>>'my.javers.comparator.ZasCatchZone#26a7b76d', (1).'my.javers.comparator.ZasCatchZone#4abdb505'>>'my.javers.comparator.ZasCatchZone#7ce6a65d', (0).'my.javers.comparator.ZasCatchZone#1500955a'>>'my.javers.comparator.ZasCatchZone#e874448']}
2. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'areas', containerChanges:[(2).'my.javers.comparator.ZasCatchArea#7113b13f'>>'my.javers.comparator.ZasCatchArea#45820e51', (1).'my.javers.comparator.ZasCatchArea#42d8062c'>>'my.javers.comparator.ZasCatchArea#6043cd28', (0).'my.javers.comparator.ZasCatchArea#cb51256'>>'my.javers.comparator.ZasCatchArea#59906517']}
package my.javers.comparator;
public class ZasCatchArea {
String catchArea;
public String getCatchArea() {
return catchArea;
}
public void setCatchArea(String catchArea) {
this.catchArea = catchArea;
}
}
public class ZasCatchZone {
String catchZone;
public String getCatchZone() {
return catchZone;
}
public void setCatchZone(String catchZone) {
this.catchZone = catchZone;
}
}
public class ZasFish {
String fischName;
List<ZasCatchZone> zones = new ArrayList<ZasCatchZone>();
List<ZasCatchArea> areas = new ArrayList<ZasCatchArea>();
public String getFischName() {
return fischName;
}
public void setFischName(String fischName) {
this.fischName = fischName;
}
public List<ZasCatchZone> getZones() {
return zones;
}
public void setZones(List<ZasCatchZone> zones) {
this.zones = zones;
}
public List<ZasCatchArea> getAreas() {
return areas;
}
public void setAreas(List<ZasCatchArea> areas) {
this.areas = areas;
}
}
public class ZasCatchAreaComparator implements
CustomPropertyComparator<ZasCatchArea, ValueChange> {
public ValueChange compare(ZasCatchArea left, ZasCatchArea right,
GlobalId affectedCdoId, Property propertyName) {
if (left.getCatchArea().equals(right.getCatchArea()))
return null;
return new ValueChange(affectedCdoId, propertyName.getName(), left, right);
}
}
public class ZasCatchZoneComparator implements
CustomPropertyComparator<ZasCatchZone, ValueChange> {
public ValueChange compare(ZasCatchZone left, ZasCatchZone right,
GlobalId affectedCdoId, Property propertyName) {
if (left.getCatchZone().equals(right.getCatchZone()))
return null;
return new ValueChange(affectedCdoId, propertyName.getName(), left, right);
}
}
public class MyComparator {
public static void main(String[] args) {
Javers javers = JaversBuilder.javers()
.registerCustomComparator(new ZasCatchAreaComparator(), ZasCatchArea.class)
.registerCustomComparator(new ZasCatchZoneComparator(), ZasCatchZone.class)
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build();
ZasFish fisch1 = new ZasFish();
ZasFish fisch2 = new ZasFish();
ZasCatchZone z1 = new ZasCatchZone();
z1.setCatchZone("zone1");
ZasCatchZone z2 = new ZasCatchZone();
z2.setCatchZone("zone2");
ZasCatchZone z3 = new ZasCatchZone();
z3.setCatchZone("zone3");
fisch1.getZones().add(z1);
fisch1.getZones().add(z2);
fisch1.getZones().add(z3);
ZasCatchArea a1 = new ZasCatchArea();
a1.setCatchArea("area1");
ZasCatchArea a2 = new ZasCatchArea();
a2.setCatchArea("area2");
ZasCatchArea a3 = new ZasCatchArea();
a3.setCatchArea("area3");
fisch1.getAreas().add(a1);
fisch1.getAreas().add(a2);
fisch1.getAreas().add(a3);
ZasCatchZone z4 = new ZasCatchZone();
z4.setCatchZone("zone3");
ZasCatchZone z5 = new ZasCatchZone();
z5.setCatchZone("zone2");
ZasCatchZone z6 = new ZasCatchZone();
z6.setCatchZone("zone1");
fisch2.getZones().add(z4);
fisch2.getZones().add(z5);
fisch2.getZones().add(z6);
ZasCatchArea a4 = new ZasCatchArea();
a4.setCatchArea("area3");
ZasCatchArea a5 = new ZasCatchArea();
a5.setCatchArea("area1");
ZasCatchArea a6 = new ZasCatchArea();
a6.setCatchArea("area2");
fisch2.getAreas().add(a4);
fisch2.getAreas().add(a5);
fisch2.getAreas().add(a6);
Diff diff = javers.compare(fisch1, fisch2);
System.out.println(diff);
}
}
I think I founded a solution for my issue. If I register values and value objects like this
final Javers javers = JaversBuilder.javers()
.registerCustomComparator(new ZasCatchAreaComparator(), ZasCatchArea.class)
.registerCustomComparator(new ZasCatchZoneComparator(), ZasCatchZone.class)
.registerValue(ZasCatchArea.class).registerValue(ZasCatchZone.class).registerValueObject(ZasFish.class)
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build();
Then I get as diff
1. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'zones', containerChanges:[(2).'my.javers.comparator.ZasCatchZone#19bef4e5'>>'my.javers.comparator.ZasCatchZone#3f1abed', (1).'my.javers.comparator.ZasCatchZone#e37f307f'>>'my.javers.comparator.ZasCatchZone#2ad1e8a5', (0).'my.javers.comparator.ZasCatchZone#2ccd3209'>>'my.javers.comparator.ZasCatchZone#c0fd1f30']}
2. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'areas', containerChanges:[(2).'my.javers.comparator.ZasCatchArea#48115f4e'>>'my.javers.comparator.ZasCatchArea#a1efa37', (1).'my.javers.comparator.ZasCatchArea#c08d9768'>>'my.javers.comparator.ZasCatchArea#d65a5a2', (0).'my.javers.comparator.ZasCatchArea#bb03583'>>'my.javers.comparator.ZasCatchArea#1ebaaab0']}
And as I don't have any ValueChange in this case I can ignore ListChange -> my Lists are identical.

OSMdroid bounds marker

////OSMdroid centered on the markers////
I add markers, I need to map the maximum increases or decreases in such a way that all markers were visible
my code:
public class mapcode extends Activity {
globalvar appState;
int stats=0;
private MapView mapView;
private IMapController mapController;
private SimpleLocationOverlay mMyLocationOverlay;
private ScaleBarOverlay mScaleBarOverlay;
ItemizedIconOverlay<OverlayItem> currentLocationOverlay;
DefaultResourceProxyImpl resourceProxy;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.map);
appState = ((globalvar) getApplicationContext());
mapView = (MapView) this.findViewById(R.id.mapview);
mapView.setTileSource(TileSourceFactory.MAPNIK);
// mapView.setBuiltInZoomControls(true); //кнопка ZOOM +-
mapView.setMultiTouchControls(true);
mapController = this.mapView.getController();
mapController.setZoom(2);
this.mMyLocationOverlay = new SimpleLocationOverlay(this);
this.mapView.getOverlays().add(mMyLocationOverlay);
this.mScaleBarOverlay = new ScaleBarOverlay(this);
this.mapView.getOverlays().add(mScaleBarOverlay);
// this.mapView
/////////////////
resourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
GeoPoint currentLocation = new GeoPoint(55.860863,37.115046);
GeoPoint currentLocation2 = new GeoPoint(63.557413,-156.102119);
OverlayItem myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation);
Drawable myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.a);
myLocationOverlayItem.setMarker(myCurrentLocationMarker);
// myLocationOverlayItem.setMarkerHotspot(HotspotPlace.CENTER); //no working/
final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
items.add(myLocationOverlayItem);
myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation2);
myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.a);
myLocationOverlayItem.setMarker(myCurrentLocationMarker);
// myLocationOverlayItem.setMarkerHotspot(HotspotPlace.CENTER); // no working
items.add(myLocationOverlayItem);
currentLocationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
return true;
}
public boolean onItemLongPress(final int index, final OverlayItem item) {
return true;
}
}, resourceProxy);
this.mapView.getOverlays().add(this.currentLocationOverlay);
}
I added two markers, but only one is visible:
and I need to osmdroid is centered and immediately showed both marker
I think you want something like this:
int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLong = Integer.MAX_VALUE;
int maxLong = Integer.MIN_VALUE;
ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
for (OverlayItem item : items) {
GeoPoint point = item.getPoint();
if (point.getLatitudeE6() < minLat)
minLat = point.getLatitudeE6();
if (point.getLatitudeE6() > maxLat)
maxLat = point.getLatitudeE6();
if (point.getLongitudeE6() < minLong)
minLong = point.getLongitudeE6();
if (point.getLongitudeE6() > maxLong)
maxLong = point.getLongitudeE6();
}
BoundingBoxE6 boundingBox = new BoundingBoxE6(maxLat, maxLong, minLat, minLong);
mMapView.zoomToBoundingBox(boundingBox);
You can calculate boundingBox by BoundingBox.fromGeoPoints(geoPoints)
fun zoomToBounds(points: List<LatLng>) {
val geoPoints = points.map { GeoPoint(it.latitude, it.longitude) }
val boundingBox = BoundingBox.fromGeoPoints(geoPoints)
mapView.zoomToBoundingBox(boundingBox, true)
}
It is also possible to have some paddings by using zoomtoBoundingBox overloaded method and setting the pBorderSizeInPixels parameter
public double zoomToBoundingBox(
final BoundingBox pBoundingBox,
final boolean pAnimated,
final int pBorderSizeInPixels,
final double pMaximumZoom,
final Long pAnimationSpeed
)

List and Map in java programing

I need to convert:
List<Map>([{1,2},{2,3}])
To:
List<List>([[1,2],[2,3]])
Can anyone help me with example for this ...
Thanks
I would suggest making a list of specific objects instead of a raw list that the get(0) returns the key and get(1) the value as follows:
List<List<Pair>> convert(List<Map<Integer,Integer> mapList){
List<List<Pair>> listOfList = new ArrayList<List<Pair>>();
for(Map<Integer,Integer> map:mapList){
List<Pair> list = new ArrayList<Pair>();
for(Entry<Integer,Integer> e:map.entrySet()){
list.add(Pair(e.getKey(),e.getValue());
}
listOfList.add(list);
}
return listOfList;
}
class Pair{
Integer first;
Integer second;
//constructor
}
You can try the following Code:
import java.util.*;
class ListOfMapToListOfList
{
public static List<List> toList(List<Map<Integer,Integer>> lList)//method to convert List<Map> to List<List>
{
List<List> list = new ArrayList<List>();
for (int i = 0 ; i < lList.size() ; i++)
{
Map<Integer,Integer> map = lList.get(i);
List<Integer> aList = new ArrayList<Integer>();
Set<Integer> keySet = map.keySet();
for (Integer key : keySet)
{
aList.add(key);
aList.add(map.get(key));
}
list.add(aList);
}
return list;
}
public static void main(String[] args) //main body
{
List<Map<Integer,Integer>> list1 = new ArrayList<Map<Integer,Integer>>();
Map<Integer,Integer> map1 = new HashMap<Integer,Integer>();
map1.put(1,2);
Map<Integer,Integer> map2 = new HashMap<Integer,Integer>();
map2.put(1,2);
list1.add(map1);list1.add(map2);
System.out.println(list1);
System.out.println(toList(list1));//Conversion is done here..and out put is shown.
}
}