0

我的应用程序中有一个 Listview,它由自定义适配器和自定义对象填充了 textview 和 imageview,现在我希望当我单击 listview 上的图像时,它应该在另一个活动中以全屏方式打开,我应该怎么做?

我有一个套接字连接 API,它带来了一个名为 image 的字节数组,我将它添加到列表视图中。

这是代码-->

@Override
                public void onBinaryMessage(byte[] image)
                {


                Bitmap receivedImage=BitmapFactory.decodeByteArray(image,0,image.length);
                    float scale=1;

                int width  = receivedImage.getWidth();
                    int height = receivedImage.getHeight();
                    float scaleHeight = (float)height/(float)200;
                    float scaleWidth  = (float)width /(float)200;
                    if (scaleWidth < scaleHeight) 
                        {scale = scaleHeight;}
                    else
                    {
                        scale = scaleWidth;
                    }

                   Bitmap bitmaped = Bitmap.createScaledBitmap(receivedImage, (int)(width/scale), (int)(height/scale), true);
                addImage(new Message(bitmaped,false,false));

现在,当单击时,我应该将什么传递给意图,因为我可以获得列表视图中的这个图像,根据我当前的代码,我可以在 listview textView 元素中烤文本。这是代码-->

  listView1.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Log.v("Module Item Trigger", "Module item was triggered");


                   Toast.makeText(getApplicationContext(),"this is ==>",Toast.LENGTH_SHORT).show();
                }
            });
4

1 回答 1

1

在 Activity 内部,ListView您可以在选择时执行onItemClickListenerbyte[]操作Bitmap

Intent intent = new Intent(myListActivity., ImageActivity.class);
Bundle bundle = new Bundle();
bundle.putByteArray("image", imageArray);
intent.putExtras(bundle);
startActivity(intent);

基本上,这会启动另一个 Activity,byte[]Bundle.

然后在显示全屏图像的 Activity 中,您可以从中byte[]取出Bundle并将其解码为Bitmap

@Override
protected void onCreate(Bundle bundle)
{
    if(bundle != null)
    {
        byte[] image = bundle.getByteArray("image");
        Bitmap receivedImage = BitmapFactory.decodeByteArray(image,0,image.length);

        // Do something with receivedImage
    }
}

希望有帮助!

于 2013-08-01T14:00:07.747 回答