Nis*_*hah 9 android universal-image-loader android-maps-v2
我正在开发新的Google Map v2 API.
我使用ImageLoader在Marker上动态显示图像.
但问题是当我使用Universal Image Loader的onLoadingComplete()时,ImageView既不会自动也不会手动失效.
下次如果单击相同的标记,将从通用图像加载器的缓存中显示图像.
下面是我的CustomInfoWindowAdapter代码:
private class CustomInfoWindowAdapter implements InfoWindowAdapter {
@Override
public View getInfoContents(Marker marker) {
return null;
}
@Override
public View getInfoWindow(Marker marker) {
final View mWindow = getLayoutInflater().inflate(R.layout.custom_info_window, null);
render(marker, mWindow);
return mWindow;
}
private void render(final Marker marker, View view) {
final String url = markers.get(marker.getId()).getStrProfilePic();
final ImageView image = ((ImageView) view.findViewById(R.id.badge));
Log.e(TAG, "URL : " + url);
if ( url != null && !url.equalsIgnoreCase("null")
&& !url.equalsIgnoreCase("")) {
imageLoader.displayImage(url, image, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
((ImageView) view).invalidate();
}
});
} else {
image.setImageResource(R.drawable.noimage);
}
final String title = marker.getTitle();
final TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}
final String snippet = marker.getSnippet();
final TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
if (snippet != null) {
snippetUi.setText(snippet);
} else {
snippetUi.setText("");
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我添加Marker时,我将Marker Ids存储在HashTable中.从他们的我会得到照片的URL.
我在类级别获取了一个Marker对象,并使用该对象更新了Marker信息.
我已经自定义了我的类,如下所示更新ImageView:
private class CustomInfoWindowAdapter implements InfoWindowAdapter {
private View view;
public CustomInfoWindowAdapter() {
view = getLayoutInflater().inflate(R.layout.custom_info_window, null);
}
@Override
public View getInfoContents(Marker marker) {
if ( YourClassName.this.marker != null &&
ClassName.this.marker.isInfoWindowShown() ) {
YourClassName.this.marker.hideInfoWindow();
YourClassName.this.marker.showInfoWindow();
}
return null;
}
@Override
public View getInfoWindow(final Marker marker) {
YourClassName.this.marker = marker;
final String url = markers.get(marker.getId()).getStrProfilePic();
final ImageView image = ((ImageView) view.findViewById(R.id.badge));
if ( url != null && !url.equalsIgnoreCase("null")
&& !url.equalsIgnoreCase("")) {
imageLoader.displayImage(url, image, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
getInfoContents(marker);
}
});
} else {
image.setImageResource(R.drawable.noimage);
}
final String title = marker.getTitle();
final TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}
final String snippet = marker.getSnippet();
final TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
if (snippet != null) {
snippetUi.setText(snippet);
} else {
snippetUi.setText("");
}
return view;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5523 次 |
| 最近记录: |