我有一個應用程序顯示地圖上的標記,我定製了infowindow來顯示創建的地方,標題,描述和圖片的內容,這些數據通過內容訪問提供者,我的問題一切都很好,直到我從數據庫中刪除記錄,應用程序變得瘋狂或破碎,或者只是奇怪的識別記錄ID等等等等 這個問題顯然是在infowindow代碼定製中,因爲要刪除它一切正常工作,創建,刪除,創建標記等......但即使我已經嘗試過沒有給出錯誤。定製InfowindowAdapter添加來自內容提供者的圖像
無間道代碼:
class MyInfoWindowAdapter implements InfoWindowAdapter {
View v;
MyInfoWindowAdapter() {
v = getLayoutInflater().inflate(R.layout.custom_info, null);
}
@SuppressWarnings("deprecation")
@Override
public View getInfoWindow(final Marker marker) {
MapaLugaresActivity.this.marker = marker;
c.requery();
TextView tvTitulo = (TextView) v.findViewById(R.id.tituloi);
tvTitulo.setText(marker.getTitle());
// TextView tvDescr = (TextView) v.findViewById(R.id.descripcioni);
// tvDescr.setText(marker.getSnippet());
ImageView imgi = (ImageView) v.findViewById(R.id.imgi);
if (marker.getSnippet() != null && marker != null
&& c.getCount() > 0) {
try {
if (c.moveToFirst()) {
c.moveToPosition(Integer.valueOf(marker.getSnippet()) - 1);
String img = c.getString(c.getColumnIndex("foto"));
if (img != null) {
resizedBitmap = DecodeImagen
.decodeSampledBitmapFromFile(img, 100, 100);
imgi.setAdjustViewBounds(true);
imgi.setImageBitmap(resizedBitmap);
} else {
imgi.setAdjustViewBounds(true);
imgi.setImageResource(R.drawable.paisaje);
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
// imgi.setImageResource(R.drawable.rdlv);
Typeface fuente = Typeface.createFromAsset(getAssets(),
"TravelingTypewriter.ttf");
tvTitulo.setTypeface(fuente);
// tvDescr.setTypeface(fuente);
return v;
}
@Override
public View getInfoContents(Marker marker) {
if (MapaLugaresActivity.this.marker != null
&& MapaLugaresActivity.this.marker.isInfoWindowShown()) {
MapaLugaresActivity.this.marker.hideInfoWindow();
MapaLugaresActivity.this.marker.showInfoWindow();
}
return null;
}
}
添加標記:
@SuppressWarnings("deprecation")
public void addMarker() {
map.clear();
c.requery();
if (c.getCount() > 0) {
c.moveToFirst();
do {
latlong = new LatLng(c.getFloat(c.getColumnIndex("latitud")),
c.getFloat(c.getColumnIndex("longitud")));
final MarkerOptions marker = new MarkerOptions().title(c
.getString(c.getColumnIndex("titulo")));
marker.snippet(c.getString(c.getColumnIndex("_id")));
marker.position(latlong);
map.addMarker(marker).showInfoWindow();
} while (c.moveToNext());
} else {
Toast.makeText(MapaLugaresActivity.this, "Añada un nuevo lugar",
Toast.LENGTH_SHORT).show();
}
}
我感謝您提前幫助下,花了幾天試圖找到解決辦法,我認爲是時候尋求幫助, 謝謝。我的編程經驗有限,希望您諒解
PS:我已上載的情況下,任何人想要去分析它在GitHub上的項目:d
在活動MapaLugaresActivity
https://github.com/Shochlves/rdlv
代碼Image infowindow:
https://lh5.ggpht.com/eBgrw0riQxfGph4FhxXvMRDxzYjlvdWw6L6qRqg_L1oV9yPGHPW9wV2Cal7zVGj1-HY=h900-rw
刪除數據庫中的行後,您是否正在重新加載「Cursor」? – CommonsWare
我不這樣做嗎? NotifyChange()?原諒我對這一點的無知,並感謝您的及時回覆 – Asuanzes
我不能告訴你你應該在這種情況下做什麼,因爲我對你的應用程序不夠了解。但是,如果你更新了你的'Cursor',你還需要重新構建你的所有標記,因爲你正在存儲一個'Cursor'特定的位置。 – CommonsWare