android GridView (图片+文字)OnItemClickListener中怎样得到图片并显示在对话框中 我想实现的功能是,点击GridView的Item,把数据(ImageView和TextView的值)传递到对话框中显示,现在我只实现了传递TextView的值,怎样在对话框中显示所点击的图片? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 itemclick有个索引,通过索引把图片获取出来,然后把获取出来的图片放在对话框里就可以了 通过OnItemClick postion 获取图片, ImageView 显示 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() {@Overridepublic 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 blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} return true;} 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 Ubuntu(64bit)如何安装arm-eabi-gcc v4.43安装包 android代码混淆问题 怎么看event log? android 自学开发第一天 就遇到这么大问题,给看看啊,谢了 从VC++过来的人,我得怎么入手安卓 请问android如何让父窗口上背景的长宽 自动适应 和它上面子窗口所占长宽的大小一样呢? 如何让 ImageView 反显? 如何实现一个只有广播和service的android应用没有activity 求软件更新完成后,首次启动弹出更新说明的方法 三星手机拍照旋转问题 关于读取email数据库德权限问题 跪求android中水平仪的实例
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;
}
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