欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android用simpleAdapter来直接显示Bitmap图片

程序员文章站 2022-03-29 14:07:43
...

SimpleAdapter定义:

 

ArrayList<HashMap<String, Object>> mFileList = new ArrayList<HashMap<String, Object>>();

SimpleAdapter mFileSimpleAdapter = new SimpleAdapter(this, mFileList, R.layout.file_listview_item, new String[] { "icon", "name" }, new int[] {
				R.id.file_icon, R.id.file_name });
		mFileSimpleAdapter.setViewBinder(new ViewBinder() {
			
			@Override
			public boolean setViewValue(View view, Object data, String textRepresentation) {
				// TODO Auto-generated method stub
				if((view instanceof ImageView) & (data instanceof Bitmap)){
					ImageView imageView = (ImageView)view;
					Bitmap mBitmap = (Bitmap)data;
					imageView.setImageBitmap(mBitmap);
					return true;
				}
				return false;
			}
		});

 

HashMap<String, Object> map = new HashMap<String, Object>();
map.put("icon", (Object)mBitmap);
map.put("name", mTempFile.getName());
mFileList.add(map);