GWT - cells values after Button ClickEvent in whole table the same - gwt

My GWT-project is a simple calendar. You can add a date by clicking on a table cell, which is opening a dialog to enter a name and the description.
The date will wrote to the tablecell, when you click on "OK" or cancel with "Abbrechen".
My code (build in Eclipse):
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.HTMLTable.Cell;
import com.google.gwt.user.client.ui.RootPanel;
public class ShowCase implements EntryPoint {
int a = 24; // Anzahl Zeit-Zeilen (Normalfall 24 -> 0:00 - 23:00)
int start = 7;
int end = 21;
DecoratorPanel panel = new DecoratorPanel();
Grid t = new Grid((a + 1), 8); //
String days[] = { " ", "Montag", "Dienstag", "Mittwoch", "Donnerstag",
"Freitag", "Samstag", "Sonntag" };
String data = null, str1 = null, str2 = null;
DialogBox dialog = new DialogBox();
Grid dialoggrid = new Grid(3, 2); // Grid-Layout für gesamte DialogBox
Label lname = new Label("Name");
Label lbeschr = new Label("Beschreibung");
TextBox tbname = new TextBox();
TextBox tbbeschr = new TextBox();
Button ok = new Button("OK");
Button cancel = new Button("Abbrechen");
int indexrow, indexcol;
DialogBox leer = new DialogBox();
Button okleer = new Button("OK");
public void onModuleLoad() {
t.setBorderWidth(1);
t.setCellSpacing(0);
for (int row = 0; row < (a + 1); row++) {
for (int col = 0; col < 8; col++) {
if (col == 0) {
int z = row - 1;
System.out.println("Spalte 0 Zeit setzen: " + row);
t.setText(row, col, z + ":00"); // Spalte 0 Zeit setzen
} else {
t.setText(row, col, "");
}
t.setText(0, col, days[col]); // Tage aus days in Zeile 0 setzen
t.getCellFormatter().setWidth(row, 0, "50px");
t.getCellFormatter().setWidth(row, col, "150px");
}
} // end for(int row=0...)
panel.add(t);
RootPanel.get("content").add(panel);
t.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println("Neuer Klick!");
Cell cell = ((HTMLTable) event.getSource()).getCellForEvent(event);
System.out.println("Cell cell HTML Table");
/*if (data.equals("1")){
tbname.setText(text);
tbbeschr.setText(null);
}*/
System.out.println("data1: " + data);
// Uhrzeit-Spalte und Wochentagsreihe absichern
if(!(cell.getRowIndex() == 0) && !(cell.getCellIndex() ==0)){
System.out.println("Get Index(): " + cell.getRowIndex() + "," + cell.getCellIndex()); // Ausgabe von Reihe und Spalte
final int indexrow = cell.getRowIndex();
final int indexcol = cell.getCellIndex();
// Dialog belegen und anzeigen
dialoggrid.setCellSpacing(0);
dialoggrid.setCellPadding(0);
tbname.setText(null);
tbbeschr.setText(null);
System.out.println("TBName: " + tbname.getText());
System.out.println("TBBeschr: " + tbbeschr.getText());
dialoggrid.setWidget(0, 0, lname);
dialoggrid.setWidget(1, 0, lbeschr);
dialoggrid.setWidget(2, 0, ok);
dialoggrid.setWidget(0, 1, tbname);
dialoggrid.setWidget(1, 1, tbbeschr);
dialoggrid.setWidget(2, 1, cancel);
dialog.setWidget(dialoggrid);
dialog.center();
dialog.setModal(false);
if(tbname.getText().equals(null)){
System.out.println("if tbname.getText equals null");
}
System.out.println("Dialog show");
dialog.show();
ok.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println("ok Click");
// Überprüfen ob TextBox Name und Beschreibung nicht leer sind
if ((!tbname.getText().equals(null)) && (!tbbeschr.getText().equals(null))) {
System.out.println("Wenn tbname & tbbeschr nicht leer sind");
str1 = tbname.getText();
str2 = tbbeschr.getText();
data = str1 + ", " + str2;
t.setText(indexrow, indexcol, data);
dialog.hide();
System.out.println("#1: "+data+"#");
data = null;
System.out.println("#2: "+data+"#");
} else {
System.out.println("leer!");
leer.setText("Felder duerfen nicht leer sein!");
leer.add(okleer);
leer.center();
leer.setModal(true);
leer.show();
okleer.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event){
System.out.println("okleer click");
leer.hide();
}
});
} // end else
}
}); // end ok.addClickHandler
cancel.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println("cancel Click");
dialog.hide();
tbname.setText(null);
tbbeschr.setText(null);
}
}); // end cancel.addClickHandler
} // end if(!(cellindex) && !(rowindex) =0 )
} // end public void OnClick()
}); // end t.addClickHandler
} // end onModuleLoad(}
The problem is, that, by entering the name & description in the dialog and click "OK", it overwrites all clicked cells (also the canceled dialog cells) with the values from my current dialog.
Some testcases with output in the console (by OK-Click it makes even more OK-Clicks for each clicked cell):
Neuer Klick!
Cell cell HTML Table
data1: null
Get Index(): 1,1
TBName:
TBBeschr:
Dialog show
ok Click
Wenn tbname & tbbeschr nicht leer sind
#1: rt, qw#
#2: null#
Neuer Klick!
Cell cell HTML Table
data1: null
Get Index(): 1,2
TBName:
TBBeschr:
Dialog show
ok Click
Wenn tbname & tbbeschr nicht leer sind
#1: gh, tz#
#2: null#
ok Click
Wenn tbname & tbbeschr nicht leer sind
#1: gh, tz#
#2: null#
Why? Or is there a better possibility to "manage" the code?

You need to use HandlerRegistration for your Click handler. As you are not clearing the the click handler, that is why it is calling the earlier events also..
Refer below links for further details:
GWT HandlerRegistration
similar issue
It seems you are quite new to GWT. Here is the working solution:
package com.my.first.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.HTMLTable.Cell;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class ShowCase implements EntryPoint {
int a = 24; // Anzahl Zeit-Zeilen (Normalfall 24 -> 0:00 - 23:00)
int start = 7;
int end = 21;
DecoratorPanel panel = new DecoratorPanel();
Grid t = new Grid((a + 1), 8); //
String days[] = { " ", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag" };
String data = null, str1 = null, str2 = null;
DialogBox dialog = new DialogBox();
Grid dialoggrid = new Grid(3, 2); // Grid-Layout für gesamte DialogBox
Label lname = new Label("Name");
Label lbeschr = new Label("Beschreibung");
TextBox tbname = new TextBox();
TextBox tbbeschr = new TextBox();
Button ok = new Button("OK");
Button cancel = new Button("Abbrechen");
HandlerRegistration okHandlerRegistration;
int indexrow, indexcol;
DialogBox leer = new DialogBox();
Button okleer = new Button("OK");
public void onModuleLoad() {
t.setBorderWidth(1);
t.setCellSpacing(0);
for (int row = 0; row < (a + 1); row++) {
for (int col = 0; col < 8; col++) {
if (col == 0) {
int z = row - 1;
System.out.println("Spalte 0 Zeit setzen: " + row);
t.setText(row, col, z + ":00"); // Spalte 0 Zeit setzen
} else {
t.setText(row, col, "");
}
t.setText(0, col, days[col]); // Tage aus days in Zeile 0 setzen
t.getCellFormatter().setWidth(row, 0, "50px");
t.getCellFormatter().setWidth(row, col, "150px");
}
} // end for(int row=0...)
panel.add(t);
RootPanel.get("content").add(panel);
t.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println("Neuer Klick!");
Cell cell = ((HTMLTable) event.getSource()).getCellForEvent(event);
System.out.println("Cell cell HTML Table");
/*
* if (data.equals("1")){ tbname.setText(text);
* tbbeschr.setText(null); }
*/
System.out.println("data1: " + data);
// Uhrzeit-Spalte und Wochentagsreihe absichern
if (!(cell.getRowIndex() == 0) && !(cell.getCellIndex() == 0)) {
System.out.println("Get Index(): " + cell.getRowIndex() + "," + cell.getCellIndex()); // Ausgabe
// von
// Reihe
// und
// Spalte
final int indexrow = cell.getRowIndex();
final int indexcol = cell.getCellIndex();
// Dialog belegen und anzeigen
dialoggrid.setCellSpacing(0);
dialoggrid.setCellPadding(0);
tbname.setText(null);
tbbeschr.setText(null);
System.out.println("TBName: " + tbname.getText());
System.out.println("TBBeschr: " + tbbeschr.getText());
dialoggrid.setWidget(0, 0, lname);
dialoggrid.setWidget(1, 0, lbeschr);
dialoggrid.setWidget(2, 0, ok);
dialoggrid.setWidget(0, 1, tbname);
dialoggrid.setWidget(1, 1, tbbeschr);
dialoggrid.setWidget(2, 1, cancel);
dialog.setWidget(dialoggrid);
dialog.center();
dialog.setModal(false);
if (tbname.getText().equals(null)) {
System.out.println("if tbname.getText equals null");
}
System.out.println("Dialog show");
dialog.show();
if (okHandlerRegistration != null) {
okHandlerRegistration.removeHandler();
}
okHandlerRegistration = ok.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println("ok Click");
// Überprüfen ob TextBox Name und Beschreibung nicht
// leer sind
if ((!tbname.getText().equals(null)) && (!tbbeschr.getText().equals(null))) {
System.out.println("Wenn tbname & tbbeschr nicht leer sind");
str1 = tbname.getText();
str2 = tbbeschr.getText();
data = str1 + ", " + str2;
t.setText(indexrow, indexcol, data);
dialog.hide();
System.out.println("#1: " + data + "#");
data = null;
System.out.println("#2: " + data + "#");
} else {
System.out.println("leer!");
leer.setText("Felder duerfen nicht leer sein!");
leer.add(okleer);
leer.center();
leer.setModal(true);
leer.show();
okleer.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println("okleer click");
leer.hide();
}
});
} // end else
}
}); // end ok.addClickHandler
cancel.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println("cancel Click");
dialog.hide();
tbname.setText(null);
tbbeschr.setText(null);
}
}); // end cancel.addClickHandler
} // end if(!(cellindex) && !(rowindex) =0 )
} // end public void OnClick()
}); // end t.addClickHandler
} // end onModuleLoad(}
}

Related

Changing scenes with Alert Boxes

I am writing a quiz application which will feature multiple different classes including a separate class for each question. I want to use Alert Boxes to give the user the option to move onto the next question, so when I press proceed to move onto the first question, however it wont change to the next scene and I dont quite understand how the buttonType works?
Any help would be appreciated
package pkg1;
import java.io.*;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Alert.*;
import javafx.scene.layout.*;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import javafx.stage.Window;
public class Register {
Stage stage;
public Register (Stage b){
stage = b;
}
public void start(Stage stage){
stage.setTitle("Registration");
GridPane gridPane = createRegisterPane();
addUIControls(gridPane);
Scene scene = new Scene(gridPane, 800, 500);
stage.setScene(scene);
stage.show();
}
private GridPane createRegisterPane() {
GridPane gridPane = new GridPane();
gridPane.setAlignment(Pos.CENTER);
gridPane.setPadding(new Insets(40, 40, 40, 40));
gridPane.setHgap(10);
gridPane.setVgap(10);
return gridPane;
}
private void addUIControls(GridPane gridPane) {
// Add Header
Label headerLabel = new Label("Registration");
headerLabel.setFont(Font.font("Arial", FontWeight.BOLD, 24));
gridPane.add(headerLabel, 0,0,2,1);
GridPane.setHalignment(headerLabel, HPos.CENTER);
GridPane.setMargin(headerLabel, new Insets(20, 0,20,0));
// FULL NAME
Label fnamelabel = new Label("Full Name : ");
gridPane.add(fnamelabel, 0,1);
// FULL NAME TEXT
TextField fnamefield = new TextField();
fnamefield.setPrefHeight(40);
gridPane.add(fnamefield, 1,1);
fnamefield.setPromptText(" - Enter your full name - ");
// EMAIL
Label emaillabel = new Label("Email: ");
gridPane.add(emaillabel, 0, 2);
// EMAIL TEXT
TextField emailfield = new TextField();
emailfield.setPrefHeight(40);
gridPane.add(emailfield, 1, 2);
emailfield.setPromptText(" - Enter your Email - ");
// USERNAME
Label usernamelabel = new Label("Username: ");
gridPane.add(usernamelabel, 0, 3);
// USERNAME TEXT
TextField usernamefield = new TextField();
usernamefield.setPrefHeight(40);
gridPane.add(usernamefield, 1, 3);
usernamefield.setPromptText(" - Enter your username - ");
// PASSWORD
Label passwordlabel = new Label("Password: ");
gridPane.add(passwordlabel, 0, 4);
// PASSWORD TEXT
PasswordField passwordfield = new PasswordField();
passwordfield.setPrefHeight(40);
gridPane.add(passwordfield, 1, 4);
passwordfield.setPromptText(" - Enter your password - ");
// SUBMIT BUTTON
Button submitButton = new Button("Submit");
submitButton.setPrefHeight(40);
submitButton.setDefaultButton(true);
submitButton.setPrefWidth(100);
gridPane.add(submitButton, 0, 5, 4, 2);
GridPane.setHalignment(submitButton, HPos.CENTER);
GridPane.setMargin(submitButton, new Insets(20, 0,20,0));
submitButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
if(fnamefield.getText().isEmpty()) {
ErrorAlert(Alert.AlertType.ERROR,
gridPane.getScene().getWindow(), "Error!", "Please enter your full name.");
return;
}
if(usernamefield.getText().isEmpty()) {
ErrorAlert(Alert.AlertType.ERROR,
gridPane.getScene().getWindow(), "Error!", "Please enter your username");
return;
}
if(emailfield.getText().isEmpty()) {
ErrorAlert(Alert.AlertType.ERROR,
gridPane.getScene().getWindow(), "Error!", "Please enter your Email");
return;
}
if(passwordfield.getText().isEmpty()) {
ErrorAlert(Alert.AlertType.ERROR,
gridPane.getScene().getWindow(), "Error!", "Please enter your password");
return;
}
String fullname = fnamefield.getText();
String email = emailfield.getText();
String username = usernamefield.getText();
String password = passwordfield.getText();
String all = fullname + "," + email + "," + username + "," + password;
try{
FileWriter fw = new FileWriter ("F:/NEW/1/src/pkg1/Register.txt",true);
PrintWriter out = new PrintWriter (fw);
out.println(all);
out.close();
}
catch (Exception e){
System.out.println("Error " + e);
}
showAlert(Alert.AlertType.CONFIRMATION, gridPane.getScene().getWindow(), "Registration Succesful!", "Welcome " + fnamefield.getText());
}
});
}
//alert box which is called
private void ErrorAlert(Alert.AlertType alertType, Window owner, String
title, String message){
Alert AlertError = new Alert (AlertType.ERROR);
AlertError.setTitle(title);
AlertError.setHeaderText(null);
AlertError.setContentText(message);
AlertError.initOwner(owner);
AlertError.show();
}
private void showAlert(Alert.AlertType alertType, Window owner, String title, String message) {
Alert alert = new Alert(alertType.CONFIRMATION);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.initOwner(owner);
alert.show();
ButtonType b1 = new ButtonType ("Proceed");
ButtonType b2 = new ButtonType ("Cancel");
ButtonType b3 = new ButtonType ("Back to Main Menu");
alert.getButtonTypes().setAll(b1,b2,b3);
if (alert.getResult() == b1) {
new QuestionOne(stage).start(stage);
}else if (alert.getResult() == b2){
new Register(stage).start(stage);
}else {
new Register(stage).start(stage);
//new Main (stage).start(stage);
}
}
public static void main(String[] args) {
launch(args);
}
}
Set the button types before showing the alert and use Dialog.showAndWait to "wait" for the result:
...
alert.initOwner(owner);
ButtonType b1 = new ButtonType("Proceed");
ButtonType b2 = new ButtonType("Cancel");
ButtonType b3 = new ButtonType("Back to Main Menu");
alert.getButtonTypes().setAll(b1,b2,b3);
Optional<ButtonType> result = alert.showAndWait();
ButtonType resButton = result.orElse(null);
if (resButton == b1) {
...
} else if (resButton == b2) {
...
} else if (resButton == b3) {
...
}
Also as mentioned previously: A Application class without a constructor that takes no parameters cannot be launched. Your main method won't work.

add a timer and carry forward its value to the next activity

how to add a timer to an activity and carry forward its values to the next activity?
I have a timer in my ShuffleButtons.class but when i move on to the next activity ShuffleButtons1.class, the timer value starts from zero. Can somebody tell me how to pass on the timer value to the next activity?
Below is my code :
import java.util.ArrayList;
import java.util.Collections;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class ShuffleButtons extends Activity {
int id = 1;
static Toast button_press;
int a = 0;
private TextView timerValue;
private long startTime = 0L;
private Handler customHandler = new Handler();
long timeInMilliseconds = 0L;
long timeSwapBuff = 0L;
long updatedTime = 0L;
#SuppressLint("ShowToast")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.shuffle );
timerValue = (TextView) findViewById(R.id.timerValue);
button_press= Toast.makeText(this, "1 Presssed", Toast.LENGTH_SHORT);
//create another two linear layouts which will host 5 buttons horizontally
LinearLayout top_compte = (LinearLayout)findViewById(R.id.top_compte);
LinearLayout bottom_calculator = (LinearLayout)findViewById(R.id.bottom_calculator);
// Create an ArrayList to hold the Button objects that we will create
ArrayList<Button> buttonList = new ArrayList<Button>();
// Create the Buttons, set their text as numeral value of the index variable
for (int i = 0; i < 4; i++) {
final Button b = new Button(this);
b.setText("" + (i+1));
b.setGravity(Gravity.CENTER_HORIZONTAL);
b.setId(i+1); // Set an id to Button
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dealWithButtonClick(b);
}
public void dealWithButtonClick(Button b) {
switch(b.getId()) {
case 1:
if (a==0) {
startTime = SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerThread, 0);
a=1;
}
button_press.setText("1 Pressed");
button_press.show();
break;
case 2:
if (a==1) {
a=2;
button_press.setText("2 Pressed");
button_press.show();
}else {
button_press.setText("You Pressed the wrong button");
button_press.show();
}
break;
case 3:
if (a==2) {
a=3;
button_press.setText("3 Pressed");
button_press.show();
}else {
button_press.setText("You Pressed the wrong button");
button_press.show();
}
break;
case 4:
if (a==3) {
timeSwapBuff += timeInMilliseconds;
customHandler.removeCallbacks(updateTimerThread);
a=4;
button_press.setText("Good Going");
button_press.show();
// here i move on from ShuffleButtons.class to ShuffleButtons1.class
Intent intent = new Intent(getApplicationContext(),ShuffleButtons1.class);
startActivity(intent);
finish();
}else {
button_press.setText("You Pressed the wrong button");
button_press.show();
}
break;
}
}
});
buttonList.add(b);
}
// Shuffle
Collections.shuffle(buttonList);
for (int i = 0; i < 4; i++) {
// Add the first five Buttons to top_compte
// Add the last five Buttons to bottom_calculator
if (i < 2) {
top_compte.addView(buttonList.get(i));
} else {
bottom_calculator.addView(buttonList.get(i));
}
}
}
// Generates and returns a valid id that's not in use
public int generateUniqueId(){
View v = findViewById(id);
while (v != null){
v = findViewById(++id);
}
return id++;
}
private Runnable updateTimerThread = new Runnable() {
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime / 1000);
int mins = secs / 60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
timerValue.setText("" + mins + ":"
+ String.format("%02d", secs) + ":"
+ String.format("%03d", milliseconds));
customHandler.postDelayed(this, 0);
}
};
}
Don't pass your Timer.
Start your timer in a separate Service, which means to let it run in background.
Make the timer globally accessible using Singleton pattern or custom Application class.
And then access it whenever and wherever you need it.
That's the cleverer way to do it. See this if you are not familiar with the Android Service component.

C# Web Form: GridView disappears while MessageBox is showing

I have 3 GridViews, each inside a separate tab. Every row in the GridView is associated with a LinkButton, and when it's clicked a MessageBox are popping up, showing the content on that particular row.
The problem is that when the MessageBox pops up the GridView disappears, and when MessageBox is closed GridView then comes back.
This problem doesn't occur if GridView is used without any tabs and is placed outside the TabControl. Here is my code:
protected void Page_Load(object sender, EventArgs e)
{
TabControl TheTabCtrl = new TabControl("InfoTabCtrl");
for (var i = 0; i < 3; i++)
{
GridView newGridView = new GridView();
//generate dynamic id
newGridView.ID = String.Concat("GridView", i);
newGridView.AutoGenerateColumns = false;
newGridView.RowDataBound += new GridViewRowEventHandler(OnRowDataBound);
//if (!this.IsPostBack)
//{
BoundField bfield = new BoundField();
bfield.HeaderText = "Id";
bfield.DataField = "Id";
newGridView.Columns.Add(bfield);
bfield = new BoundField();
bfield.HeaderText = "Name";
bfield.DataField = "Name";
newGridView.Columns.Add(bfield);
TemplateField tfield = new TemplateField();
tfield.HeaderText = "Country";
newGridView.Columns.Add(tfield);
tfield = new TemplateField();
tfield.HeaderText = "View";
newGridView.Columns.Add(tfield);
//}
this.BindGrid(newGridView, i);
string myString = i.ToString();
TabPage BasicPage1 = new TabPage(myString, myString);
BasicPage1.Controls.Add(newGridView);
TheTabCtrl.Tabs.Add(BasicPage1);
}
if (!this.IsPostBack)
{
string value = Request.Form[TheTabCtrl.Id + "_SelectedTab"];
if (!string.IsNullOrEmpty(value))
{
try
{
TheTabCtrl.SelectedTab = TheTabCtrl.Tabs.IndexOf(TheTabCtrl.Tabs.Where(x => x.Id == value).First());
}
catch
{
}
}
}
form1.Controls.Add(TheTabCtrl.GetControl);
}
private void BindGrid(GridView newGridView, int id)
{
string[][,] jaggedArray = new string[3][,]
{
new string[,] { {"John Hammond", "United States"}, {"Mudassar Khan", "India"}, {"Suzanne Mathews", "France"}, {"Robert Schidner", "Russia"} },
new string[,] { {"Zoey Melwick", "New Zeeland"}, {"Bryan Robertson", "England"}, {"Beth Stewart", "Australia"}, {"Amanda Rodrigues", "Portugal"} },
new string[,] { {"Glenda Becker", "Germany"}, {"Despoina Athanasiadis", "Greece"}, {"Alexandra López", "Spain"}, {"David Bouchard", "Canada"} }
};
for (int row = 0; row < jaggedArray.Length; row++)
{
if (id != row) continue;
DataTable dt = new DataTable();
// Share the same headlines
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
for (int pair = 0; pair < jaggedArray[row].Length / 2; pair++)
{
dt.Rows.Add(pair + 1, jaggedArray[row][pair, 0], jaggedArray[row][pair, 1]);
}
string myPage = string.Concat(row, "page");
string myString = row.ToString();
newGridView.DataSource = dt;
newGridView.DataBind();
}//End for Row
}//BindGrid
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtCountry = new TextBox();
txtCountry.ID = "txtCountry";
txtCountry.Text = (e.Row.DataItem as DataRowView).Row["Country"].ToString();
e.Row.Cells[1].Width = 200;
e.Row.Cells[2].Controls.Add(txtCountry);
LinkButton lnkView = new LinkButton();
lnkView.ID = "lnkView";
lnkView.Text = "View";
lnkView.Click += ViewDetails;
lnkView.CommandArgument = (e.Row.DataItem as DataRowView).Row["Id"].ToString();
e.Row.Cells[3].Controls.Add(lnkView);
}
}
protected void ViewDetails(object sender, EventArgs e)
{
LinkButton lnkView = (sender as LinkButton);
GridViewRow row = (lnkView.NamingContainer as GridViewRow);
string id = lnkView.CommandArgument;
string name = row.Cells[1].Text;
string country = (row.FindControl("txtCountry") as TextBox).Text;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Id: " + id + " Name: " + name + " Country: " + country + "')", true);
}
So how can I show a MessageBox without GridView disappearing?

CustomdataGrid is not being displayed in the browser

I have a custom datagrid which is defined as follows
public class CustomDataGrid<T> extends DataGrid<T> {
private static final int PAGE_SIZE = 10;
public CustomDataGrid(ProvidesKey<T> keysProvider) {
super(PAGE_SIZE, keysProvider);
}
public CustomDataGrid() {
super(PAGE_SIZE);
}
public void redrawRow(int absRowIndex) {
int relRowIndex = absRowIndex - getPageStart();
checkRowBounds(relRowIndex);
setRowData(absRowIndex, Collections.singletonList(getVisibleItem(relRowIndex)));
}
}
I am using ui binder and in my xml file I have defined the elements as follows
<com:CustomDataGrid ui:field="commissionListDataGrid"></com:CustomDataGrid>
Now the custom datagrid is initialised as follows
#UiField
CustomDataGrid commissionListDataGrid;
private final Set<Long> showingFriends = new HashSet<Long>();
private Column<ServiceCategorywiseCommissionDetails, String> viewFriendsColumn;
private Column<ServiceCategorywiseCommissionDetails, String> serviceType;
public ZoneCommissionListView() {
commissionListDataGrid = new CustomDataGrid<ServiceCategorywiseCommissionDetails>(new ProvidesKey<ServiceCategorywiseCommissionDetails>() {
#Override
public Object getKey(ServiceCategorywiseCommissionDetails item) {
return item == null ? null : item.getId();
}
});
commissionListDataGrid.setWidth("100%");
commissionListDataGrid.setEmptyTableWidget(new Label("Empty data"));
commissionListDataGrid.setHeight("100%");
// commissionListLayoutPanel = new SimpleLayoutPanel();
initCommissionListDataGrid();
// commissionListLayoutPanel.add(commissionListDataGrid);
//RootLayoutPanel.get().add(commissionListLayoutPanel);
}
#Override
public Widget asWidget() {
return this.widget;
}
#Override
public void setUiHandlers(ZoneCommissionListUiHandlers uiHandlers) {
this.uiHandlers = uiHandlers;
}
public void initCommissionListDataGrid() {
// View friends.
SafeHtmlRenderer<String> anchorRenderer = new AbstractSafeHtmlRenderer<String>() {
#Override
public SafeHtml render(String object) {
SafeHtmlBuilder sb = new SafeHtmlBuilder();
sb.appendHtmlConstant("(").appendEscaped(object).appendHtmlConstant(")");
return sb.toSafeHtml();
}
};
viewFriendsColumn = new Column<ServiceCategorywiseCommissionDetails, String>(new ClickableTextCell(anchorRenderer)) {
#Override
public String getValue(ServiceCategorywiseCommissionDetails object) {
if (showingFriends.contains(object.getId())) {
return "-";
} else {
return "+";
}
}
};
viewFriendsColumn.setFieldUpdater(new FieldUpdater<ServiceCategorywiseCommissionDetails, String>() {
#Override
public void update(int index, ServiceCategorywiseCommissionDetails object, String value) {
if (showingFriends.contains(object.getId())) {
showingFriends.remove(object.getId());
} else {
showingFriends.add(object.getId());
}
// Redraw the modified row.
commissionListDataGrid.redrawRow(index);
}
});
// First name.
serviceType = new Column<ServiceCategorywiseCommissionDetails, String>(new TextCell()) {
#Override
public String getValue(ServiceCategorywiseCommissionDetails object) {
return object.getServiceType();
}
};
commissionListDataGrid.setTableBuilder(new CustomTableBuilder());
commissionListDataGrid.setHeaderBuilder(new CustomHeaderBuilder());
// commissionListDataGrid.setFooterBuilder(new CustomFooterBuilder());
// GWT.log("list size is " + ContactDatabase.get().getDataProvider().getList().size());
// commissionListDataGrid.setRowData(ContactDatabase.get().getDataProvider().getList());
// Button button = new Button();
// button.setText("hello");
// commissionListLayoutPanel.add(commissionListDataGrid);
this.widget = uiBinder.createAndBindUi(this);
}
private class CustomTableBuilder extends AbstractCellTableBuilder<ServiceCategorywiseCommissionDetails> {
private final String childCell = " ";
private final String rowStyle;
private final String selectedRowStyle;
private final String cellStyle;
private final String selectedCellStyle;
#SuppressWarnings("deprecation")
public CustomTableBuilder() {
super(commissionListDataGrid);
// Cache styles for faster access.
Style style = commissionListDataGrid.getResources().style();
rowStyle = style.evenRow();
selectedRowStyle = " " + style.selectedRow();
cellStyle = style.cell() + " " + style.evenRowCell();
selectedCellStyle = " " + style.selectedRowCell();
}
public void buildRowImpl(ServiceCategorywiseCommissionDetails rowValue, int absRowIndex) {
buildServiceTypeRow(rowValue, absRowIndex, false);
GWT.log("Inside build row impl");
// Display list of friends.
if (showingFriends.contains(rowValue.getId())) {
TableRowBuilder row = startRow();
TableCellBuilder th = row.startTH();
th.text("").endTH();
TableCellBuilder th2 = row.startTH();
th2.text("Service Name").endTH();
TableCellBuilder th3 = row.startTH();
th3.text("SuperZone Commission").endTH();
TableCellBuilder th4 = row.startTH();
th4.text("Zone Commission").endTH();
row.endTR();
List<ServiceCommissionDetails> friends = rowValue.getServiceCommissionDetails();
for (ServiceCommissionDetails friend : friends) {
buildServiceCommissionDetailRow(friend, absRowIndex, true);
}
}
}
#SuppressWarnings("deprecation")
private void buildServiceTypeRow(ServiceCategorywiseCommissionDetails rowValue, int absRowIndex, boolean isFriend) {
GWT.log("inside build service Type row");
SelectionModel<? super ServiceCategorywiseCommissionDetails> selectionModel = commissionListDataGrid.getSelectionModel();
boolean isSelected = (selectionModel == null || rowValue == null) ? false : selectionModel.isSelected(rowValue);
boolean isEven = absRowIndex % 2 == 0;
StringBuilder trClasses = new StringBuilder(rowStyle);
if (isSelected) {
trClasses.append(selectedRowStyle);
}
// Calculate the cell styles.
String cellStyles = cellStyle;
if (isSelected) {
cellStyles += selectedCellStyle;
}
if (isFriend) {
cellStyles += childCell;
}
TableRowBuilder row = startRow();
row.className(trClasses.toString());
/*
* Checkbox column.
*
* This table will uses a checkbox column for selection. Alternatively, you can call dataGrid.setSelectionEnabled(true) to
* enable mouse selection.
*/
TableCellBuilder td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
td.endTD();
/*
* View friends column.
*
* Displays a link to "show friends". When clicked, the list of friends is displayed below the contact.
*/
td = row.startTD();
td.className(cellStyles);
if (!isFriend) {
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
renderCell(td, createContext(1), viewFriendsColumn, rowValue);
}
td.endTD();
// First name column.
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if (isFriend) {
td.text(rowValue.getServiceType());
} else {
renderCell(td, createContext(2), serviceType, rowValue);
}
td.endTD();
// Last name column.
row.endTR();
}
#SuppressWarnings("deprecation")
private void buildServiceCommissionDetailRow(ServiceCommissionDetails rowValue, int absRowIndex, boolean isFriend) {
GWT.log("inside build service commission detail row");
// Calculate the row styles.
// boolean isSelected = (selectionModel == null || rowValue == null)
// ? false : selectionModel.isSelected(rowValue);
// boolean isEven = absRowIndex % 2 == 0;
StringBuilder trClasses = new StringBuilder(rowStyle);
// if (isSelected) {
// trClasses.append(selectedRowStyle);
// }
// Calculate the cell styles.
String cellStyles = cellStyle;
// cellStyles += selectedCellStyle;
cellStyles += childCell;
TableRowBuilder row = startRow();
row.className(trClasses.toString());
/*
* Checkbox column.
*
* This table will uses a checkbox column for selection. Alternatively, you can call dataGrid.setSelectionEnabled(true) to
* enable mouse selection.
*/
TableCellBuilder td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
td.endTD();
/*
* View friends column.
*
* Displays a link to "show friends". When clicked, the list of friends is displayed below the contact.
*/
// First name column.
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
td.text(rowValue.getServiceName());
td.endTD();
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
td.text(rowValue.getSuperZoneCommission());
td.endTD();
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
td.text(rowValue.getZoneCommission());
td.endTD();
// Last name column.
row.endTR();
}
}
private class CustomHeaderBuilder extends AbstractHeaderOrFooterBuilder<ServiceCategorywiseCommissionDetails> {
private Header<String> firstNameHeader = new TextHeader("Co mmission List");
public CustomHeaderBuilder() {
super(commissionListDataGrid, false);
setSortIconStartOfLine(false);
}
#Override
protected boolean buildHeaderOrFooterImpl() {
Style style = commissionListDataGrid.getResources().style();
String groupHeaderCell = "Header Cell";
// Add a 2x2 header above the checkbox and show friends columns.
TableRowBuilder tr = startRow();
tr.startTH().colSpan(2).rowSpan(2).className(style.header() + " " + style.firstColumnHeader());
tr.endTH();
/*
* Name group header. Associated with the last name column, so clicking on the group header sorts by last name.
*/
// Get information about the sorted column.
ColumnSortList sortList = commissionListDataGrid.getColumnSortList();
ColumnSortInfo sortedInfo = (sortList.size() == 0) ? null : sortList.get(0);
Column<?, ?> sortedColumn = (sortedInfo == null) ? null : sortedInfo.getColumn();
boolean isSortAscending = (sortedInfo == null) ? false : sortedInfo.isAscending();
// Add column headers.
tr = startRow();
buildHeader(tr, firstNameHeader, serviceType, sortedColumn, isSortAscending, false, false);
tr.endTR();
return true;
}
private void buildHeader(TableRowBuilder out, Header<?> header, Column<ServiceCategorywiseCommissionDetails, ?> column, Column<?, ?> sortedColumn, boolean isSortAscending, boolean isFirst,
boolean isLast) {
// Choose the classes to include with the element.
Style style = commissionListDataGrid.getResources().style();
boolean isSorted = (sortedColumn == column);
StringBuilder classesBuilder = new StringBuilder(style.header());
if (isFirst) {
classesBuilder.append(" " + style.firstColumnHeader());
}
if (isLast) {
classesBuilder.append(" " + style.lastColumnHeader());
}
// if (column.isSortable()) {
// classesBuilder.append(" " + style.sortableHeader());
// }
if (isSorted) {
classesBuilder.append(" " + (isSortAscending ? style.sortedHeaderAscending() : style.sortedHeaderDescending()));
}
// Create the table cell.
TableCellBuilder th = out.startTH().className(classesBuilder.toString());
// Associate the cell with the column to enable sorting of the
// column.
enableColumnHandlers(th, column);
// Render the header.
Context context = new Context(0, 2, header.getKey());
renderSortableHeader(th, context, header, isSorted, isSortAscending);
// End the table cell.
th.endTH();
}
}
public void setCommissionListDataGrid(ListDataProvider<ServiceCategorywiseCommissionDetails> dataProvider) {
GWT.log("inside set commissionListDataGrid size is " + dataProvider.getList().size());
commissionListDataGrid.setRowData(dataProvider.getList());
}
And I have a method in the presenter which calls the method set CommissionListDataGrid and sets its row value.
While doing this the data grid is not displayed. However if i add simplelayoutpanel in the following way in the constructor 'ZoneCommissionListView()'
RootPanel.get().add(commissionListLayoutPanel);
Then the data grid is displayed .What exactly am I missing .Any suggestion would be appreciated
DataGrid requires to be put in a LayoutPanel or Panel that implements
the ProvidesResize interface to be visible.
Source
And the SimpelLayoutPanel which you tested also implements the ProvidesResize Interface.

Google maps API v2 Android, not drawing polygon when offline

I have a test application that I draw a Polygon using google maps API.
The problem is that, when I have no cache of any maps (new installed application) the Polygon does not draw.
Its not a problem not having the maps loaded, but I do need the Polygons drawn in my screen.
Is there a way I can do that?
Sry for my bad english
Heres the code I have:
package ngvl.testegmaps_v2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import ngvl.testegmaps_v2.VO.GeoPosicionamento;
import ngvl.testegmaps_v2.VO.Layer;
import ngvl.testegmaps_v2.VO.Secao;
import ngvl.testegmaps_v2.VO.Talhao;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Polygon;
import com.google.android.gms.maps.model.PolygonOptions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class MainActivity extends FragmentActivity {
private List<Secao> secoes;
private List<Polygon> poligonos = new ArrayList<Polygon>();
private HashMap<String,Object[]> informacoes = new HashMap<String,Object[]>();
private GoogleMap map;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = fragment.getMap();
map.getUiSettings().setRotateGesturesEnabled(false);
// Setting a click event handler for the map
LatLng latLng = new LatLng(-20.9957152, -47.3241304);
// map.addMarker(new
// MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)).title("Av. Paulista").snippet("São Paulo"));
configuraPosicao(map, latLng);
Button button = (Button)findViewById(R.id.button1);
// Register the onClick listener with the implementation above
button.setOnClickListener(mCorkyListener);
}
private void configuraPosicao(GoogleMap map, LatLng latLng) {
/*
* 3D map.moveCamera( CameraUpdateFactory.newLatLngZoom(latLng, 15));
* map.animateCamera( CameraUpdateFactory.zoomTo(10), 2000, null);
*
* CameraPosition cameraPosition = new CameraPosition.Builder()
* .target(latLng) .zoom(17) .bearing(90) .tilt(45) .build();
*
* map.animateCamera( CameraUpdateFactory.newCameraPosition(
* cameraPosition));
*/
map.setMapType(GoogleMap.MAP_TYPE_NONE);
// map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17.0f));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
try {
String json = readFileAsString("geo.json");
Gson gson = new Gson();
this.secoes = gson.fromJson(json, new TypeToken<List<Secao>>() {
}.getType());
json = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
escrevePoligons(map);
}
private String readFileAsString(String fileName) throws IOException {
InputStream is = getAssets().open(fileName);
if (is != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
} finally {
is.close();
}
return sb.toString();
} else {
return "";
}
}
private void escrevePoligons(GoogleMap map) {
float stroke = (float) 1.5;
for (Secao secao : secoes) {
for (Talhao talhao : secao.getTalhoes()) {
for (Layer layer : talhao.getLayers()) {
// PolygonOptions rectOptions = new PolygonOptions();
List<LatLng> latlngs = new ArrayList<LatLng>();
for (GeoPosicionamento geoPosicionamento : layer.getGeoPosicionamentos()) {
latlngs.add(new LatLng(geoPosicionamento.getLatitude()
.setScale(7, BigDecimal.ROUND_HALF_EVEN)
.doubleValue(), geoPosicionamento
.getLongitude()
.setScale(7, BigDecimal.ROUND_HALF_EVEN)
.doubleValue()));
}
int color = 0x1F00FF00;
int color2 = 0x5F000000;
PolygonOptions polygonOptions = new PolygonOptions()
.fillColor(color).addAll(latlngs)
.strokeColor(color2).strokeWidth(stroke);
Polygon p = map.addPolygon(polygonOptions);
poligonos.add(p);
informacoes.put( p.getId(), new Object[]{ secao, talhao , layer } );
//System.out.println(polygonOptions.getPoints());
polygonOptions = null;
latlngs = null;
}
}
}
this.secoes = null;
// String mUrl =
// "https://khms0.google.com.br/kh/v=124&src=app&z={z}&x={x}&y={y}";
// MyUrlTileProvider mTileProvider = new MyUrlTileProvider(256, 256,
// mUrl);
// mTileProvider.tilesRange();
// map.addTileOverlay(new
// TileOverlayOptions().tileProvider(mTileProvider).zIndex(-1f));
//String mUrl = "http://a.tile.openstreetmap.org/{z}/{x}/{y}.png";
//MyUrlTileProvider mTileProvider = new MyUrlTileProvider(256, 256, mUrl);
//map.addTileOverlay(new TileOverlayOptions().tileProvider(mTileProvider).zIndex(-1f));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-20.9957152, -47.3241304), 14));
// TileProvider tileProvider = TileProviderFactory.getTileProvider();
// map.addTileOverlay(new
// TileOverlayOptions().tileProvider(tileProvider));
// map.moveCamera(CameraUpdateFactory.newLatLngZoom(new
// LatLng(-20.9957152, -47.3241304), 15));
map.setOnMapClickListener(new OnMapClickListener()
{
public void onMapClick(LatLng point)
{
Polygon p = isPointInPolygon(point);
if( p != null){
p.setFillColor(getRandomColor());
Object[] clicado = informacoes.get( p.getId() );
Secao secao_clicada = (Secao) clicado[0];
Talhao talhao_clicada = (Talhao) clicado[1];
Layer layer_clicada = (Layer) clicado[2];
//System.out.println(secao_clicada);
//System.out.println(talhao_clicada);
//System.out.println(layer_clicada);
//System.out.println("=======================");
StringBuilder texto = new StringBuilder();
texto.append("Seção: " + secao_clicada.getDesc() + "\n");
texto.append("Talhão: " + talhao_clicada.getTalhao() + "\n");
texto.append("Variedade: " + talhao_clicada.getVariedade() + " - " + talhao_clicada.getDescVariedade() + "\n");
texto.append("Layer: " + layer_clicada.getSequencia() + "\n");
//Toast.makeText(MainActivity.this, texto , Toast.LENGTH_LONG).show();
addMarker(point,texto);
}//else
//Toast.makeText(MainActivity.this,"Clicou fora da Área de um Poligono", Toast.LENGTH_LONG).show();
}
});
}
public void addMarker(LatLng point, StringBuilder texto) {
/*map.addMarker(new MarkerOptions().position(point).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
.title("Caracteristicas: ")
.snippet( texto );
*/
Toast.makeText(MainActivity.this, texto , Toast.LENGTH_LONG).show();
}
private Polygon isPointInPolygon(LatLng tap) {
for( Polygon p : poligonos){
int intersectCount = 0;
List<LatLng> vertices = p.getPoints();
for(int j=0; j<vertices.size()-1; j++) {
if( rayCastIntersect(tap, vertices.get(j), vertices.get(j+1)) ) {
intersectCount++;
}
}
if(((intersectCount % 2) == 1)){
return p;
}
}
return null;// odd = inside, even = outside;
}
private boolean rayCastIntersect(LatLng tap, LatLng vertA, LatLng vertB) {
double aY = vertA.latitude;
double bY = vertB.latitude;
double aX = vertA.longitude;
double bX = vertB.longitude;
double pY = tap.latitude;
double pX = tap.longitude;
if ( (aY>pY && bY>pY) || (aY<pY && bY<pY) || (aX<pX && bX<pX) ) {
return false; // a and b can't both be above or below pt.y, and a or b must be east of pt.x
}
double m = (aY-bY) / (aX-bX); // Rise over run
double bee = (-aX) * m + aY; // y = mx + b
double x = (pY - bee) / m; // algebra is neat!
return x > pX;
}
private OnClickListener mCorkyListener = new OnClickListener() {
public void onClick(View v) {
// do something when the button is clicked
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-20.9957152, -47.3241304), 14));
}
};
public int getRandomColor() {
int color;
Random rnd = new Random();
color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256),
rnd.nextInt(256));
return color;
}
}
Setting map type to MAP_TYPE_NONE like example above does not solve the problem
I will this as marked solved by using Maps Forge Open Source API
If someone did with Google Maps Api please share and I would change the answer.
The answer I found is that its impossible to render or access anything without rendering the map first (online or via cache)
This is actually a bug of GoogleMaps Api v2 for Android.
It is referenced here:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=5017
Star it if you want to accelerate the bug fix!