我想实现的功能是,点击GridView的Item,把数据(ImageView和TextView的值)传递到对话框中显示,现在我只实现了传递TextView的值,怎样在对话框中显示所点击的图片?

解决方案 »

  1.   

    itemclick有个索引,通过索引把图片获取出来,然后把获取出来的图片放在对话框里就可以了
      

  2.   

    通过OnItemClick postion 获取图片, ImageView 显示
      

  3.   


    public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
    final String mImagePath;
    mImagePath = path.get(arg2);
    File fl=new File(mImagePath);
    BitmapFactory.Options opt=new BitmapFactory.Options();
    opt.inPreferredConfig=Config.RGB_565;
    opt.inPurgeable=true;
    opt.inSampleSize=1;
    opt.inInputShareable=true;
    try {
    FileInputStream fin=new FileInputStream(fl);
    BufferedInputStream bin=new BufferedInputStream(fin);
    Bitmap bm=BitmapFactory.decodeStream(bin,null,opt);
    ImageView iv=new ImageView(OrderActivity.this);
    iv.setImageBitmap(bm);
    iv.setMaxWidth(500);  
     iv.setMaxHeight(500);  
    AlertDialog.Builder builder = new Builder(OrderActivity.this);
    builder.setView(iv);
    builder.setPositiveButton("确定",new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
    dialog.cancel();
    }
    });
    AlertDialog alertDialog = builder.create();  
    alertDialog.show();  
    WindowManager m = getWindowManager(); 
    Display d = m.getDefaultDisplay(); 
    WindowManager.LayoutParams p = getWindow().getAttributes(); 
    p.height = (int) (d.getHeight() * 0.6); 
    p.width = (int) (d.getWidth() * 0.8); 
    alertDialog.getWindow().setAttributes(p);  
    bin.close();
    }catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

    return true;
    }
      

  4.   

    LayoutInflater inflater = getLayoutInflater();
       View layout = inflater.inflate(R.layout.dialog,
         (ViewGroup) findViewById(R.id.dialog));   new AlertDialog.Builder(this).setTitle("自定义布局").setView(layout)
         .setPositiveButton("确定", null)
         .setNegativeButton("取消", null).show();布局那块自己放imageview,对话框的形式定义很多元化,比较灵活
    博客园有个空间,可以看看:http://www.cnblogs.com/salam/archive/2010/11/15/1877512.html