我有一个应用程序显示地图上的标记,我定制了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