Can't place Marker in GWT Maps with Lat & Lng - Null Pointer Exception in map.addOverlay(Marker) - gwt

I'm trying to add multiple markers to my GWT-Map. If I do it with the geocoder, it works just fine... But I also get the values from a database, so I can place them via Lat Lng.
That's the code:
public static void markerSetzen(final double lat, final double lon) {
/* Markeroptionen setzen */
MarkerOptions markeroptions = MarkerOptions.newInstance();
markeroptions.setBouncy(true);
markeroptions.setBounceGravity(0.3);
final Marker marker = new Marker(LatLng.newInstance(lat, lon),
markeroptions);
map.addOverlay(marker);
marker.addMarkerClickHandler(new MarkerClickHandler() {
#Override
public void onClick(MarkerClickEvent event) {
// popup- Fenster erstellen
map.getInfoWindow().open(
LatLng.newInstance(lat, lon),
new InfoWindowContent(image + name + "<br>" + ort
+ "<br>" + kategorie + "<br><br>"
+ beschreibung + "<br>" + web));
}
});
}
The exception is always thrown at map.addOverlay(). I check the returned doubles from the db
via syso and they're just fine...
I hope someone can help,
thanks in advance
EDIT: that is the code of the geocoder method, which does what I want:
public static void koordSuchen(final double lat, final double lon,
final String ort, final String image, final String name,
final String kategorie, final String beschreibung,
final String web, final int zoomlevel) {
// Geokodierung von Adressen herausbekommen
Geocoder geocoder = new Geocoder();
geocoder.getLatLng(ort, new LatLngCallback() {
#Override
public void onSuccess(LatLng point) {
final LatLng ortKoord = LatLng.newInstance(lat, lon);
// neuen Marker erstellen
Marker marker = new Marker(ortKoord);
// neues Marker- Overlay erstellen
map.addOverlay(marker);
// Marker Klickhandler erstellen (Bei klick auf Marker oeffnet
// sich ein Popup)
marker.addMarkerClickHandler(new MarkerClickHandler() {
#Override
public void onClick(MarkerClickEvent event) {
// popup- Fenster erstellen
map.getInfoWindow().open(
ortKoord,
new InfoWindowContent(image + name + "<br>"
+ ort + "<br>" + kategorie + "<br><br>"
+ beschreibung + "<br>" + web));
}
});
}
#Override
public void onFailure() {
}
});
}

map.addOverlay() is the first instance of the variable map in your sample code. Are you sure map is initialized?

Related

Insert sensor data from android studio into SQLite database every 1 second?

I am developing an app using Android Studio which stores the data gathered from the phone's sensors (accelerometer and gyroscope) into SQLite database. The app is working fine and the SQLite database is receiving the inserted values.
The problem now is, it is inserting too many values to the point where it inserts values every microsecond. I have tried every sampling period (SENSOR_DELAY_NORMAL,SENSOR_DELAY_UI) but to no avail. My aim is to only insert values every 1 second to reduce the computing usage. Is it possible to control the rate of data insertion and if so could you guys show me some pointers?
accelerometer & gyroscope listeners:
//Creating the sensor manager; SENSOR_SERVICE is used to access sensors.
sM = (SensorManager) getSystemService(SENSOR_SERVICE);
//Accelerometer Sensor.
accelerometer = sM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
if(accelerometer != null){
//Register sensor listener;
sM.registerListener(this, accelerometer, 100_000_000);
Log.d("TAG 1 Accelerometer ", "onCreate initializing accelerometer");
} else{
xText.setText("Accelerometer not supported");
yText.setText("Accelerometer not supported");
zText.setText("Accelerometer not supported");
}
//GYRO Sensor.
gyroscope = sM.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
if(gyroscope != null){
//Register sensor listener;
sM.registerListener(this, gyroscope, 100_000_000);
Log.d("TAG 2 Gyroscope", "onCreate initializing gyroscope");
} else{
xTextGyro.setText("GYROSCOPE not supported");
yTextGyro.setText("GYROSCOPE not supported");
zTextGyro.setText("GYROSCOPE not supported");
}
onSensorChanged():
#Override
public void onSensorChanged(SensorEvent event) {
Sensor sensorType = event.sensor;
Location location = null;
if(sensorType.getType()==Sensor.TYPE_ACCELEROMETER) {
accelX = event.values[0];
accelY = event.values[1];
accelZ = event.values[2];
xText.setText("X: " + event.values[0]);
yText.setText("Y: " + event.values[1]);
zText.setText("Z: " + event.values[2]);
xText.setText("X: " + accelX);
yText.setText("Y: " + accelY);
zText.setText("Z: " + accelZ);
} else if (sensorType.getType() == Sensor.TYPE_GYROSCOPE){
xTextGyro.setText("X: " + event.values[0]);
yTextGyro.setText("Y: " + event.values[1]);
zTextGyro.setText("Z: " + event.values[2]);
gyroX = event.values[0];
gyroY = event.values[1];
gyroZ = event.values[2];
}
DatabaseHelper class:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String SENSOR_TABLE = "SENSOR_TABLE";
public static final String COLUMN_ACCEL_X = "ACCEL_X";
public static final String COLUMN_ACCEL_Y = "ACCEL_Y";
public static final String COLUMN_ACCEL_Z = "ACCEL_Z";
public static final String COLUMN_GYRO_X = "GYRO_X";
public static final String COLUMN_GYRO_Y = "GYRO_Y";
public static final String COLUMN_GYRO_Z = "GYRO_Z";
public static final String COLUMN_CURRENT_SPEED = "CURRENT_SPEED";
private static DatabaseHelper mInstance;
public DatabaseHelper(Context context) {
super(context, String.valueOf(Calendar.getInstance().getTime())+".db", null, 1);
//Date currentTime = Calendar.getInstance().getTime();
// Log.d("TAG DATE", ""+ currentTime);
// super(context, "Live_Test.db", null, 1);
SQLiteDatabase db = this.getWritableDatabase();
}
public static DatabaseHelper getInstance(){
if(mInstance == null){
synchronized (DatabaseHelper.class){
if(mInstance == null){
mInstance = new DatabaseHelper(BaseApp.getApp());
}
}
}
return mInstance;
}
#Override
public void onCreate(SQLiteDatabase db) {
//String createTableStatement= "CREATE TABLE " + SENSOR_TABLE + "( " + COLUMN_ACCEL_X + " REAL, " + COLUMN_ACCEL_Y + " REAL, " + COLUMN_ACCEL_Z + " REAL, time DATETIME DEFAULT CURRENT_TIME)";
String createTableStatement= "CREATE TABLE " + SENSOR_TABLE + "( time DATETIME DEFAULT CURRENT_TIME, " + COLUMN_ACCEL_X + " REAL, " + COLUMN_ACCEL_Y + " REAL, " + COLUMN_ACCEL_Z + " REAL, " + COLUMN_GYRO_X + " REAL, " + COLUMN_GYRO_Y + " REAL, " + COLUMN_GYRO_Z + " REAL, " + COLUMN_CURRENT_SPEED + " REAL)";
db.execSQL(createTableStatement);
Log.d("TAG database :", "DATABASE CREATED");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+SENSOR_TABLE);
onCreate(db);
}
public void insertTable(float x, float y, float z ,float a, float b , float c, double speed){ //put onSensorChanged data to database
ContentValues contentvalues = new ContentValues();
contentvalues.put("ACCEL_X", x);
contentvalues.put("ACCEL_Y", y);
contentvalues.put("ACCEL_Z", z);
contentvalues.put("GYRO_X", a);
contentvalues.put("GYRO_Y", b);
contentvalues.put("GYRO_Z", c);
contentvalues.put("CURRENT_SPEED", speed);
getWritableDatabase().insert(SENSOR_TABLE, null, contentvalues);
}
}
Something like this should help:
#Override
public void onSensorChanged(SensorEvent sensorEvent) {
long now = System.currentTimeMillis();
if(lastSensed + SAMPLING_PERIOD_MS < now) {
// do what you want to do
saveToSQLiteDb();
lastSensed = System.currentTimeMillis();
}
}
When we register the sensor listener, I tried to keep the sampling of that to the default like SensorManager.SENSOR_DELAY_NORMAL, which is like 200,000 microseconds.
That if sentence is satisifed if we keep the SAMPLING_PERIOD_MS to something greater than the default one, so that data is saved to database only after SAMPLING_PERIOD_MS.
Keeping listener's sampling high ensures that fixed interval of delay is achieved

Android Volley with REST Api - POST will not insert into dB and respons incorrectly

I am using https://github.com/mevdschee/php-crud-api as REST Api to access my MySQL db. To access data from Android application I use Volley lib.
All works fine except POST (creating new item in db). But instead new item created I am getting JSON will all items (look like output from GET) and item is not created in dB.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "APP START");
tv = findViewById(R.id.textView);
buttonPost = findViewById(R.id.buttonPost);
buttonGet = findViewById(R.id.buttonGet);
Calendar cal = Calendar.getInstance();
SimpleDateFormat sd1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
current_date = sd1.format(new Date(cal.getTimeInMillis()));
Log.d(TAG, "current_date=" + current_date);
cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
mRequestQueue = new RequestQueue(cache, network);
mRequestQueue.start();
buttonGet.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d(TAG, "ButtonGet pressed");
tv.setText("");
getRest();
}
});
buttonPost.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d(TAG, "ButtonPost pressed");
tv.setText("");
postRest();
}
});
}
getRest()
tv.append("REST API - reading data via GET " + "\n");
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, endpointUrl, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONObject vancuraLevel1 = response.getJSONObject("restdemo");
JSONArray vancuraLevel2 = vancuraLevel1.getJSONArray("records");
int JSONlenght2 = vancuraLevel2.length();
Log.d("JSON", "JSONlenght2 =" + JSONlenght2 );
for(int n = 0; n < JSONlenght2; n++) {
Log.d("JSON", "looping " + n );
JSONArray vancuraLevel3 = vancuraLevel2.getJSONArray(n);
int JSONlenght3 = vancuraLevel3.length();
String index = vancuraLevel3.getString(0);
String datum = vancuraLevel3.getString(1);
String subjekt = vancuraLevel3.getString(2);
String ovoce = vancuraLevel3.getString(3);
Log.d("JSON", "result datum" + datum + " subjekt=" + subjekt);
tv.append("Data : " + index + "/" + datum + "/" + subjekt + "/" + ovoce + "\n");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Volley REST error " + error.toString());
tv.append("ERROR " + error.toString() +"\n");
}
});
// fire Volley request
mRequestQueue.add(jsObjRequest);
postRest(){
final String whatToInsert = "foo subjekt " + current_date;
// POST - insert data
tv.append("REST API - inserting data via POST - payload=" + whatToInsert +"\n");
StringRequest postRequest = new StringRequest(Request.Method.POST, endpointUrl, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
// response
Log.d("Response", response);
// tv.append(current_date + "\n");
tv.append("response = " + response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
// error
Log.e("Error.Response", error.getMessage());
tv.append("ERROR " + error.toString() +"\n");
}
})
{
#Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
//params.put("index", "NULL");
params.put("datum", "2017-12-30");
params.put("subjekt", whatToInsert);
params.put("ovoce", "2");
return params;
}
};
// fire Volley request
mRequestQueue.add(postRequest);
Result GET - it is OK
Result POST - fault
project is available at https://github.com/fanysoft/AndroidRESTapi
Looking closely at the code the GET method returns a JSONObject response while the POST method return a String response. The string response of the POST Method is very correct and it carries exactly the same result as the GET method result all you have to do is convert the String response to JSON object you ll have same JSONObject as the GET method
JSONObject jsonObject = new JSONObject(response);
Then you can parse the object for your result
Solved by disabling Volley cache
getRequest.setShouldCache(false);
postRequest.setShouldCache(false);

SQLite database is not updating within an application

I am developing an application. When I modify my data, the previous data is displayed and not the updated data. This is the ModifyActivity.java file:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class ModifyCountryActivity extends Activity implements OnClickListener {
private EditText titleText, dateText, timeText;
private Button updateBtn, deleteBtn;
public Calendars calendars;
private DatabaseHelper dbHelper;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Modify Record");
setContentView(R.layout.activity_modify_record);
dbHelper = new DatabaseHelper(this);
calendars = new Calendars();
titleText = (EditText) findViewById(R.id.title_edittext_modify);
timeText = (EditText) findViewById(R.id.time_edittext_modify);
dateText = (EditText) findViewById(R.id.date_edittext_modify);
updateBtn = (Button) findViewById(R.id.btn_update);
deleteBtn = (Button) findViewById(R.id.btn_delete);
Intent intent = getIntent();
String title = intent.getStringExtra("title");
String time = intent.getStringExtra("time");
String date = intent.getStringExtra("date");
titleText.setText(title);
timeText.setText(time);
dateText.setText(date);
updateBtn.setOnClickListener(this);
deleteBtn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_update:
titleText.setText(titleText.getText().toString() + " ");
timeText.setText(dateText.getText().toString() + " ");
dateText.setText(timeText.getText().toString() + " ");
calendars.set_remindertitle(titleText.getText().toString() + " ");
calendars.set_reminderdate(dateText.getText().toString() + " ");
calendars.set_remindertime(timeText.getText().toString() + " ");
dbHelper.update(calendars);
this.returnHome();
break;
case R.id.btn_delete:
dbHelper.delete(calendars);
this.returnHome();
break;
}
}
public void returnHome() {
Intent home_intent = new Intent(getApplicationContext(), CountryListActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(home_intent);
}
}
The database doesn't update. It shows the previous data again. This is the database class:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "calendar.db";
public static final String TABLE_REMINDER = "reminder";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_REMINDER_TITLE = "_remindertitle";
public static final String COLUMN_REMINDER_DESCRIPTION = "_reminderdescription";
public static final String COLUMN_REMINDER_DATE = "_reminderdate";
public static final String COLUMN_REMINDER_TIME = "_remindertime";
public static final String COLUMN_REMINDER_REPEAT = "_reminderrepeat";
public static final String COLUMN_REMINDER_SNOOZE = "_remindersnooze";
SQLiteDatabase database;
// Database Information
Class<? extends DatabaseHelper> context = getClass();
DatabaseHelper dbHelper;
// Creating table query
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_REMINDER + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
COLUMN_REMINDER_DATE + " TEXT, " + COLUMN_REMINDER_TIME + " TEXT, " + COLUMN_REMINDER_TITLE + " TEXT, "
+ COLUMN_REMINDER_DESCRIPTION + " TEXT, " + COLUMN_REMINDER_REPEAT + " TEXT, " + COLUMN_REMINDER_SNOOZE + " TEXT " + ");";
Log.i("Query", query);
db.execSQL(query);
}
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_REMINDER);
onCreate(db);
}
public ArrayList<Calendars> databaseToArrayList() {
ArrayList<Calendars> arrayList = new ArrayList();
SQLiteDatabase db = getWritableDatabase();
String query = "SELECT * FROM " + TABLE_REMINDER;
Cursor c = db.rawQuery(query, null);
c.moveToFirst();
while (!c.isAfterLast()) {
if (c.getString(c.getColumnIndex("_reminderdate")) != null) {
Calendars calendars = new Calendars();
calendars.set_reminderdate(c.getString(c.getColumnIndex(COLUMN_REMINDER_DATE)));
calendars.set_remindertime(c.getString(c.getColumnIndex(COLUMN_REMINDER_TIME)));
calendars.set_remindertitle(c.getString(c.getColumnIndex(COLUMN_REMINDER_TITLE)));
calendars.set_reminderdescription(c.getString(c.getColumnIndex(COLUMN_REMINDER_DESCRIPTION)));
calendars.set_reminderrepeat(c.getString(c.getColumnIndex(COLUMN_REMINDER_REPEAT)));
calendars.set_remindersnooze(c.getString(c.getColumnIndex(COLUMN_REMINDER_SNOOZE)));
arrayList.add(calendars);
}
c.moveToNext();
}
c.close();
db.close();
return arrayList;
}
public void remove(String id) {
String string = String.valueOf(id);
SQLiteDatabase database = getReadableDatabase();
database.execSQL("DELETE FROM " + TABLE_REMINDER + " WHERE _id = '" + string + "'");
}
public void addReminder(Calendars calendars) {
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_REMINDER_DATE, calendars.get_reminderdate());
contentValues.put(COLUMN_REMINDER_TIME, calendars.get_remindertime());
contentValues.put(COLUMN_REMINDER_TITLE, calendars.get_remindertitle());
contentValues.put(COLUMN_REMINDER_DESCRIPTION, calendars.get_reminderdescription());
contentValues.put(COLUMN_REMINDER_REPEAT, calendars.get_reminderrepeat());
contentValues.put(COLUMN_REMINDER_SNOOZE, calendars.get_remindersnooze());
SQLiteDatabase database = getReadableDatabase();
database.insert(TABLE_REMINDER, null, contentValues);
Log.i("insData", "the data has been inseted");
database.close();
}
public Cursor fetch() {
String[] columns = new String[]{COLUMN_ID, /*COLUMN_REMINDER_DATE, COLUMN_REMINDER_TIME, COLUMN_REMINDER_TITLE,*/
COLUMN_REMINDER_DESCRIPTION, COLUMN_REMINDER_REPEAT, COLUMN_REMINDER_SNOOZE};
SQLiteDatabase database = getReadableDatabase();
Cursor cursor = database.query(TABLE_REMINDER, columns, null, null, null, null, null);
if (cursor != null)
{
cursor.moveToFirst();
}
return cursor;
}
public int update(Calendars calendars) {
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_REMINDER_DATE, calendars.get_reminderdate());
contentValues.put(COLUMN_REMINDER_TIME, calendars.get_remindertime());
contentValues.put(COLUMN_REMINDER_TITLE, calendars.get_remindertitle());/*
contentValues.put(COLUMN_REMINDER_DESCRIPTION, calendars.get_reminderdescription());
contentValues.put(COLUMN_REMINDER_REPEAT, calendars.get_reminderrepeat());
contentValues.put(COLUMN_REMINDER_SNOOZE, calendars.get_remindersnooze());*/
SQLiteDatabase database = getReadableDatabase();
int i = database.update(TABLE_REMINDER, contentValues, COLUMN_ID + " = " + calendars.get_id(), null);
database.close();
return i;
}
public void delete(Calendars calendars) {
database = getReadableDatabase();
database.delete(TABLE_REMINDER, COLUMN_ID + "=" + calendars.get_id(), null);
}
}
I believe that the update button should be working fine. I am new to Android and don't know how to solve this problem. Any suggestions on how to solve it?
If you're update function returns an int, then in your onClick function, rather than typing:
dbHelper.update(calendars);
You need to type:
int update = dbHelper.update(calendars);
Or:
if (dbHelper.update(calendars) > 0) {
// do something here
}
I would recommend the latter of the options. See how you go.

Gwt CheckBoxCell check uncheck issue

I am not able to check or uncheck a Gwt CheckBoxCell . It works fine in Chrome but it doesn't work at all in mozilla . What wrong i am doing ? Please Suggest . When i am selecting selectAllHeader not able to check/uncheck in mozilla though same works in chrome.
DataGridTableRowModel headerRow = dataGridTableRowList.get(0);
E12CommonUtils.printOnConsole("IN createTableComponent================="+ headerRow);
int width = 50;
final MultiSelectionModel<DataGridTableRowModel> multiSelectionModel = new MultiSelectionModel<DataGridTableRowModel>();
this.setSelectionModel(multiSelectionModel,DefaultSelectionEventManager.<DataGridTableRowModel> createCheckboxManager(0));
multiSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler()
{
public void onSelectionChange(SelectionChangeEvent event)
{
count++;
E12CommonUtils.printOnConsole("Inside select : ");
Set<DataGridTableRowModel> set = multiSelectionModel.getSelectedSet();
Iterator it = set.iterator();
selectedValues = new StringBuffer();
selectedNames = new StringBuffer();
while (it.hasNext())
{
DataGridTableRowModel row = (DataGridTableRowModel) it.next();
E12CommonUtils.printOnConsole("Inside select = "+ row.getCellText(1));
selectedValues.append(row.getCellText(1) + ":");
E12CommonUtils.printOnConsole("AFTER APPENDING selectedValues = "+ row.getCellText(1));
selectedNames.append(row.getCellData(1).getName() + ":");
}
}
});
E12CommonUtils.printOnConsole("IN $$$$$$$$$$$$$$$$$=================135");
final Column<DataGridTableRowModel, Boolean> checkColumn = new Column<DataGridTableRowModel, Boolean>(new E12CheckBoxCell(false, false))
{
#Override
public Boolean getValue(DataGridTableRowModel dataGridTRModel)
{
boolean isSelected = multiSelectionModel.isSelected(dataGridTRModel);
E12CommonUtils.printOnConsole("checkColumn isSelected["+ isSelected + "]\tprotect["+ dataGridTRModel.getCellData(0).isProtect() + "]");
getFieldUpdater().update(0, dataGridTRModel, isSelected); // If commented deselect all works
return isSelected;
}
};
checkColumn.setFieldUpdater(new FieldUpdater<DataGridTableRowModel, Boolean>()
{
#Override
public void update(int idx,DataGridTableRowModel dataGridTRModel,Boolean value)
{
try
{
CellData cellData = dataGridTRModel.getCellData(0);
cellData.setData(String.valueOf(value));
dataGridTRModel.setCellData(0, cellData);
multiSelectionModel.setSelected(dataGridTRModel, value);
}
catch (Exception e)
{
Window.alert("Exception in checkColumn.setFieldUpdater : "+ e.getMessage());
}
}
});
CheckboxCell checkAll = new CheckboxCell();
// E12CheckBoxCell checkAll = new E12CheckBoxCell(false, false);
Header<Boolean> selectAllHeader = new Header<Boolean>(checkAll){
#Override
public Boolean getValue()
{
E12CommonUtils.printOnConsole("IN getValue()=========");
return false;
}
};
selectAllHeader.setUpdater(new ValueUpdater<Boolean>(){
#Override
public void update(Boolean selected)
{
for (DataGridTableRowModel ele : getVisibleItems())
{
E12CommonUtils.printOnConsole("IN update**************");
multiSelectionModel.setSelected(ele, selected);
}
}
});
this.addColumn(checkColumn, selectAllHeader);
this.setColumnWidth(checkColumn, 20, Unit.PX);
for (int i = 1; i < headerRow.getRowData().size(); i++)
{
final int index = i;
final String colName = headerRow.getCellData(index).getName();
width = 25;// TODO
E12CustomColumn column = new E12CustomColumn(index, false);
this.setColumnWidth(column, width + "px");
// Add a selection model to handle user selection.
ResizableHeader<DataGridTableRowModel> header = new ResizableHeader<DataGridTableRowModel>(colName, this, column) {
#Override
public String getValue()
{
return colName;
}
};
// this.addColumn(column, selectAllHeader,header);
// this.addColumn(selectAllHeader, header);
this.addColumn(column, header);
}
dataProvider.addDataDisplay(this);
dataProvider.refresh();
it may be browser compatibility issue - meta tag might help you
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
For more details follow below url -
What does <meta http-equiv="X-UA-Compatible" content="IE=edge"> do?

Add Cluster Items onClick over Expandable List View

First of all I'm sorry for my bad English :X
Iam quite a newbie in Android App development and Iam about to develope an app which gives the user informations like free park-places in town.
The app is based on Google Maps.
My Problem:
My app starts and shows a Google Maps Layout. Over an ExpandableListView the User can open a overview about the Parking-Locations.
If the user click on a Child Item in the ExpListView a new Cluster item should be generated at the MapsLayout.
How can I give the OnClick data to the MainActivity? I want that the MainActivity 'knew' which Item is clicked by the User!
Im glad about every answer :)
public class MyExpandableAdapter extends BaseExpandableListAdapter{
private Activity activity;
private ArrayList<Object> childtems;
private LayoutInflater inflater;
private ArrayList<String> parentItems, child;
// constructor
public MyExpandableAdapter(ArrayList<String> parents, ArrayList<Object> childern)
{
this.parentItems = parents;
this.childtems = childern;
}
public void setInflater(LayoutInflater inflater, Activity activity)
{
this.inflater = inflater;
this.activity = activity;
}
// method getChildView is called automatically for each child view.
// Implement this method as per your requirement
#Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
child = (ArrayList<String>) childtems.get(groupPosition);
TextView textView = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.child_view, null);
}
// get the textView reference and set the value
textView = (TextView) convertView.findViewById(R.id.textViewChild);
textView.setText(child.get(childPosition));
// set the ClickListener to handle the click event on child item
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(activity, child.get(childPosition),
Toast.LENGTH_SHORT).show();
//Tried to insert connection to MapsActivity but doesnt work!
}
});
return convertView;
}
// method getGroupView is called automatically for each parent item
// Implement this method as per your requirement
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
if (convertView == null) {
convertView = inflater.inflate(R.layout.parent_view, null);
}
((CheckedTextView) convertView).setText(parentItems.get(groupPosition));
((CheckedTextView) convertView).setChecked(isExpanded);
return convertView;
}
#Override
public Object getChild(int groupPosition, int childPosition)
{
return null;
}
#Override
public long getChildId(int groupPosition, int childPosition)
{
return 0;
}
#Override
public int getChildrenCount(int groupPosition)
{
return ((ArrayList<String>) childtems.get(groupPosition)).size();
}
#Override
public Object getGroup(int groupPosition)
{
return null;
}
#Override
public int getGroupCount()
{
return parentItems.size();
}
#Override
public void onGroupCollapsed(int groupPosition)
{
super.onGroupCollapsed(groupPosition);
}
#Override
public void onGroupExpanded(int groupPosition)
{
super.onGroupExpanded(groupPosition);
}
#Override
public long getGroupId(int groupPosition)
{
return 0;
}
#Override
public boolean hasStableIds()
{
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return false;
}
}
MapsActivity (Main)
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
private ClusterManager<MyItem> mClustermanager ;
private ArrayList<String> parentItems = new ArrayList<String>();
private ArrayList<Object> childItems = new ArrayList<Object>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpClusterer();
// Create Expandable List and set it's properties
ExpandableListView expandableList = (ExpandableListView) findViewById(R.id.expandableListView);
expandableList.setDividerHeight(2);
expandableList.setGroupIndicator(null);
expandableList.setClickable(true);
// Set the Items of Parent
setGroupParents();
// Set The Child Data
setChildData();
// Create the Adapter
MyExpandableAdapter adapter = new MyExpandableAdapter(parentItems, childItems);
adapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), this);
// Set the Adapter to expandableList
expandableList.setAdapter(adapter);
// expandableList.setOnChildClickListener();
}
// method to add parent Items
public void setGroupParents()
{
parentItems.add("Parkhäuser");
}
public void setChildData()
{
ArrayList<String> child = new ArrayList<String>();
child = new ArrayList<String>();
child.add("Park1");
child.add("Park2");
child.add("Park3");
child.add("Park4");
childItems.add(child);
}
private void setUpClusterer()
{
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(47.99481, 7.84856), 10 )) ;
//Initialisierung des Managers mit dem Context (this) und der Map
//Activity erbt von Context deswegen können wir dem Konstruktor 'this' mitgeben
mClustermanager = new ClusterManager<MyItem>(this, ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap() );
//Zeigt der Map die Listener des ClusterManagers
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap().setOnCameraChangeListener((mClustermanager));
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap().setOnMarkerClickListener(mClustermanager);
//Hinzufügen der Markierungen zum Cluster Manager
addItems() ;
}
private void addItems(){
//Startkoordinaten des ersten Markers --> Bahnhofsgarage
double lat = 47.99673 ;
double lng = 7.84152 ;
//Hinzufügen von 10 weiteren Punkten
for(int i = 1; i <14; i++){
if(i==1)
{ //Konzerthaus
lat = 47.99602 ;
lng = 7.84220;
}
if(i==2){
//Volksbank
lat = 47.99783 ;
lng = 7.84322;
}
if(i==3){
//am Bahnhof
lat = 47.99892 ;
lng = 7.84310;
}
if(i==4){
//Uni-FMF/Vf
lat = 48.00135 ;
lng = 7.84481;
}
if(i==5){
//unterlinden
lat = 47.99811 ;
lng = 7.84876;
}
if(i==6){
//schwarzwaldcity
lat = 47.99760 ;
lng = 7.85090;
}
if(i==7){
//Rotteckring
lat = 47.99618 ;
lng = 7.84732;
}
if(i==8){
//Am Zähringer Tor
lat = 47.99921 ;
lng = 7.85350;
}if(i==9){
//Karlsbau
lat = 47.99757 ;
lng = 7.85366;
}if(i==10){
//Landratsamt
lat = 47.99969 ;
lng = 7.85758;
}if(i==11){
//Schlossberg
lat = 47.99654 ;
lng = 7.85758;
}if(i==12){
//Schwabentor
lat = 47.99054 ;
lng = 7.85833;
}if(i==13){
//Am Martinstor
lat = 47.99281 ;
lng = 7.84715;
}if(i==14){
//Uni Kolleg Gebäude
lat = 47.98797 ;
lng = 7.87129;
}
MyItem offsetItem = new MyItem(lat,lng) ;
mClustermanager.addItem(offsetItem);
}
}
}
Solved! After research I make ExpandableAdpater an inner class of MapsActivity! Now i can put data between both classes and use Methods also!