android – 具有图像的Popupwindow

我需要能够在列表视图中单击一个imgview,这应该打开一个显示图像的大小的弹出窗口.我设法实现了clicklistener,但是在创建弹出窗口时仍然失败,即使只是一个测试文本视图.

在我的主要活动中,我跑

lstView.setAdapter(new CustomListViewAdapter(this,dataFromDBListe,orientation));

在我的CustomListVievAdapter中,我有我的clicklistener(可以在此时显示吐司),我有以下getView():

public View getView(int position,View convertView,ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.custom_row,null);
        holder = new ViewHolder();
        holder.title = (TextView) convertView.findViewById(R.id.title);
        holder.prev = (TextView) convertView.findViewById(R.id.prevNrDate);
        holder.prevTitle = (TextView) convertView.findViewById    (R.id.prevTitle);
        holder.next = (TextView) convertView.findViewById(R.id.nextNrDate);
        holder.nextTitle = (TextView) convertView.findViewById     (R.id.nextTitle);
        holder.picture = (ImageView) convertView.findViewById    (R.id.showPic);
        holder.prevFast = (TextView) convertView.findViewById(R.id.prev);
        holder.nextFast = (TextView) convertView.findViewById(R.id.next);
        holder.linearLayout = (LinearLayout) convertView.findViewById    (R.id.imgLay);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    testSort(holder);
    final Show item = showList.get(position);
    holder.title.setText(item.getTitle());
    holder.prev.setText(item.getPrevNr() + " - " + item.getPrevDate());
    holder.prevTitle.setText(item.getPrevTitle());
    holder.next.setText(item.getNextNr() + " - " + item.getNextDate());
    holder.nextTitle.setText(item.getNextTitle());

    if(pic) {
        holder.linearLayout.setVisibility(8);
    } if(compact) {
        holder.linearLayout.setVisibility(8);
        holder.prevTitle.setVisibility(8);
        holder.nextTitle.setVisibility(8);
    } else {
//          new DownloadImageTask(holder.picture).execute(item.getShowId());
        String path;
        if(ih.checkImg(item.getShowId())) {
            path = PATH + item.getShowId() + ".jpg";
        } else {
            path = "bla";
        }
//          DrawableManager dm = new DrawableManager();
//          dm.fetchDrawableOnThread(path,holder.picture);
        imageDownloader.download(path,holder.picture);
//          ih.download(path,holder.picture);
    }

    holder.picture.setonClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Toast.makeText(context,"IMG clicked",Toast.LENGTH_LONG).show();
                    //Show popup with full image of the clicked small img.
                }
            });

    return convertView;
}

在这里尝试了大多数常见的链接解决方案的弹出窗口,但不能使其工作.

解决方法

创建自定义对话框并在其中传递图像….
private void loadPhoto(ImageView imageView,int width,int height) {

        ImageView tempImageView = imageView;


        AlertDialog.Builder imageDialog = new AlertDialog.Builder(this);
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);

        View layout = inflater.inflate(R.layout.custom_fullimage_dialog,(ViewGroup) findViewById(R.id.layout_root));
        ImageView image = (ImageView) layout.findViewById(R.id.fullimage);
        image.setimageDrawable(tempImageView.getDrawable());
        imageDialog.setView(layout);
        imageDialog.setPositiveButton(resources.getString(R.string.ok_button),new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialog,int which) {
                dialog.dismiss();
            }

        });


        imageDialog.create();
        imageDialog.show();     
    }

custom_fullimage_dialog.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root" android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:padding="10dp">
    <ImageView android:id="@+id/fullimage" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </ImageView>

    <TextView android:id="@+id/custom_fullimage_placename"
        android:layout_width="wrap_content" android:layout_height="fill_parent"
        android:textColor="#FFF">
    </TextView>
</LinearLayout>

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...