我正在制作一个安卓应用程序,我需要在点击放大图像大小。我从服务器下载这些图像,然后在活动中以编程方式添加这些图像,从而以编程方式设置图像的id。现在我的问题是,当我将imageid发送到另一个活动以放大它时,它只接受最后一个图像的id。
因此给出了以下异常。
Unable to start activity ComponentInfo{com.emx.OnDaMove/com.emx.OnDaMove.FullImageActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x5我使用以下代码制作图像并将它们添加到表行中。
imageUrl = "http://ondamove.it/English/images/users/";
imageUrl = imageUrl + listObject.get(j).getImage();
image = new ImageView(this);
image.setPadding(20, 10, 0, 0);
image.setId(j+1);
imageId=image.getId();
tr.addView(image);clickliastener的方法如下:
private OnClickListener clickImageListener = new OnClickListener() {
public void onClick(View v) {
Intent fullScreenIntent = new Intent(v.getContext(),FullImageActivity.class);
fullScreenIntent.putExtra(ProfilePageNormalUser.class.getName(),imageId) ;
ProfilePageNormalUser.this.startActivity(fullScreenIntent);
}
};而要放大图像的活动是:
ImageView myimage = (ImageView) findViewById(R.id.imageviewEnlarged);
Intent intent = getIntent();
int imageId = (Integer) intent.getExtras().get(ProfilePageNormalUser.class.getName());
System.out.println("********"+imageId +"**********");
InputStream is = this.getResources().openRawResource(imageId);
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
Matrix imageMatrix = new Matrix();
imageMatrix.postRotate(90);
Bitmap scaledBitmap = Bitmap.createBitmap(originalBitmap, myimage.getWidth(), myimage.getHeight(), originalBitmap.getWidth(), originalBitmap.getHeight(), imageMatrix, false);
myimage.setImageBitmap(scaledBitmap);
myimage.setScaleType(ScaleType.FIT_XY);发布于 2011-11-01 17:37:00
它肯定会给出最后一个Id,因为imageId的值在每次循环中都会更新。这将在循环期间存储最后一个已知值。
你应该使用数组而不是简单的变量。
或者,您可以在onClick方法中使用v.getId。(更简单的)
https://stackoverflow.com/questions/7964546
复制相似问题