我的应用程序中有一些imageView,其中一个imageview是父图像,父图像的功能是来自另一个imageview孩子的显示图像,如果点击的话。
如果图像B1单击,那么ImageView B1的源图像显示在imageView A中,另一个imageView B可以像B1一样点击,我是如何实现的?
i使用此代码在imageview B中显示图像。
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 (MapV2InfoWindow.this.marker != null
&& MapV2InfoWindow.this.marker.isInfoWindowShown()) {
MapV2InfoWindow.this.marker.hideInfoWindow();
MapV2InfoWindow.this.marker.showInfoWindow();
}
return null;
}
@Override
public View getInfoWindow(final Marker marker) {
MapV2InfoWindow.this.marker = marker;
String url = null;
if (marker.getId() != null && markers != null && markers.size() > 0) {
if ( markers.get(marker.getId()) != null &&
markers.get(marker.getId()) != null) {
url = markers.get(marker.getId());
}
}
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.ic_launcher);
}
return view;
}
}
我收到错误
03-24 15:35:54.099: E/AndroidRuntime(8412): FATAL EXCEPTION: main
03-24 15:35:54.099: E/AndroidRuntime(8412): java.lang.NullPointerException
03-24 15:35:54.099: E/AndroidRuntime(8412): at com.ltvie.chatkrawala.MapV2InfoWindow$1.onInfoWindowClick(MapV2InfoWindow.java:125)
03-24 15:35:54.099: E/AndroidRuntime(8412): at com.google.android.gms.maps.GoogleMap$10.e(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at com.google.android.gms.maps.internal.f$a.onTransact(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at android.os.Binder.transact(Binder.java:279)
03-24 15:35:54.099: E/AndroidRuntime(8412): at eiy.a(SourceFile:82)
03-24 15:35:54.099: E/AndroidRuntime(8412): at maps.e.bl.b(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at maps.ay.o.am_(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at maps.ay.o.a(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at maps.ay.bg.b(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at maps.ay.bc.onSingleTapConfirmed(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at maps.bo.g.onSingleTapConfirmed(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at maps.bo.i.handleMessage(Unknown Source)
03-24 15:35:54.099: E/AndroidRuntime(8412): at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 15:35:54.099: E/AndroidRuntime(8412): at android.os.Looper.loop(Looper.java:130)
03-24 15:35:54.099: E/AndroidRuntime(8412): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-24 15:35:54.099: E/AndroidRuntime(8412): at java.lang.reflect.Method.invokeNative(Native Method)
03-24 15:35:54.099: E/AndroidRuntime(8412): at java.lang.reflect.Method.invoke(Method.java:507)
03-24 15:35:54.099: E/AndroidRuntime(8412): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-24 15:35:54.099: E/AndroidRuntime(8412): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-24 15:35:54.099: E/AndroidRuntime(8412): at dalvik.system.NativeStart.main(Native Method)
感谢。
答案 0 :(得分:1)
就这样做。
imageViewA.setImageDrawable( imageViewB.getDrawable() );
答案 1 :(得分:0)
为您的活动实施onClick并在 onClick 监听器上执行以下操作:
switch (key) {
case R.id.b1:
Bitmap bitmap = ((BitmapDrawable)imageViewB1.getDrawable()).getBitmap();
imageViewA.setImageBitmap(bitmap);
break;
case R.id.b2:
Bitmap bitmap = ((BitmapDrawable)imageViewB2.getDrawable()).getBitmap();
imageViewA.setImageBitmap(bitmap);
break;
case R.id.b3:
Bitmap bitmap = ((BitmapDrawable)imageViewB3.getDrawable()).getBitmap();
imageViewA.setImageBitmap(bitmap);
break;
default:
break;
}
答案 2 :(得分:0)
点击ImageViewb1时输入此代码。
Bitmap bitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap();
imageViewA.setImageBitmap(bitmap);
重复以上代码,点击B2和B3。