GridView中使用ImageView的新活动

时间:2013-02-17 11:14:15

标签: android

我正在尝试在新活动中在ImageView中显示图像,但我遇到了问题。新的活动是开放的,我可以看到图像的路径在吐司meassage,但仍然没有图像可见!可能有什么不对?

MainActivity类的一部分:

       gridview.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView parent, View v, int position, long id) {

            String[] projection = {MediaStore.Images.Media.DATA};
            cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
            int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToPosition(position);
            String imagePath = cursor.getString(columnIndex);

            // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), FullImageActivity.class);

            i.putExtra("image", imagePath);

            //Toast.makeText(MainActivity.this, "" + imagePath, Toast.LENGTH_SHORT).show();

            startActivity(i);
        }
    });

FullActivityClass:

public class FullImageActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image);

    // get intent data
    Intent i = getIntent();

    // Selected image id
    //int id = i.getExtras().getInt("image");
    //ImageAdapter imageAdapter = new ImageAdapter(this);
    String imageId = i.getExtras().getString("image");

    ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
    imageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + imageId));
    //imageView.setImageResource(imageAdapter.mThumbIds[position]);

    Toast.makeText(FullImageActivity.this, "" + imageId, Toast.LENGTH_LONG).show();
}
}

1 个答案:

答案 0 :(得分:0)

试试这个。

FullActivity.java

Bitmap bitmap =BitmapFactory.decodeFile(imageId);
imageView.setImageBitmap(bitmap);

让我知道它是否适合你......

快乐编码:)