gpt4 book ai didi

android - 如何在 AlertDialog 中显示来自 GridView 的图像?

转载 作者:行者123 更新时间:2023-11-30 03:07:15 27 4
gpt4 key购买 nike

mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> gridView, View view,
int pos, long id) {

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(view);
builder.create().show();

}
});

当我尝试运行这段代码时,在我点击一个项目后,我得到一个异常:

enter image description here

我不想从其父项中删除 View 。我只想在 AlertDialog 中显示图像。有人可以提示我该怎么做吗?

最佳答案

试试这个...

    mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> gridView, View view,
int pos, long id) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
ImageView imageView = new ImageView(gridView.getContext());
imageView.setScaleType(ImageView.ScaleType.CENTER);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
imageView.setImageBitmap(bitmap);
builder.setView(imageView);
builder.create().show();
}
});

关于android - 如何在 AlertDialog 中显示来自 GridView 的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21595736/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com