在模仿着做新浪微博的客户端,在显示最近微博的这个ListView里面的用户信息用线程获取到了,其他信息都已经放进ListView了,但是图片怎么弄去了啊?部分代码for(int i=0;i<weibo.size();i++){
Map<String,String> map = new HashMap<String,String>();
map.put("list_time", simple.format(new Date(weibo.get(i).getCreated_at())) );
map.put("list_content", weibo.get(i).getText());
map.put("list_name", weibo.get(i).getUser().getName());
map.put("list_iconurl", weibo.get(i).getUser().getProfile_image_url());
list.add(map);
}
//添加到list中去
simpleAdapter = new MySimpleAdapter(tableHostHomepage.getContext(), list, R.layout.weibo_list, new String[]{"list_time","list_content","list_name","list_iconurl"}, new int[]{R.id.list_time,R.id.list_content,R.id.list_name,R.id.list_iconurl});
homelist = (ListView)tableHostHomepage.findViewById(R.id.homepage_list);
homelist.setAdapter(simpleAdapter);
listview图片android
Map<String,String> map = new HashMap<String,String>();
map.put("list_time", simple.format(new Date(weibo.get(i).getCreated_at())) );
map.put("list_content", weibo.get(i).getText());
map.put("list_name", weibo.get(i).getUser().getName());
map.put("list_iconurl", weibo.get(i).getUser().getProfile_image_url());
list.add(map);
}
//添加到list中去
simpleAdapter = new MySimpleAdapter(tableHostHomepage.getContext(), list, R.layout.weibo_list, new String[]{"list_time","list_content","list_name","list_iconurl"}, new int[]{R.id.list_time,R.id.list_content,R.id.list_name,R.id.list_iconurl});
homelist = (ListView)tableHostHomepage.findViewById(R.id.homepage_list);
homelist.setAdapter(simpleAdapter);
listview图片android
public class WebImageView extends ImageView
{ private String mCacheFolder; private int quality; private Bitmap bitmap; public WebImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.quality = attrs.getAttributeIntValue("android", "quatity", 100); //this.mCacheFolder = "sdcard/download/images/";
}
@Override
public boolean isInEditMode() {return true;}; public WebImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
} public WebImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
} public String getmCacheFolder() {
return mCacheFolder;
} public void setmCacheFolder(String mCacheFolder) {
this.mCacheFolder = mCacheFolder;
} Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
downLoadThread = null;
if (bitmap != null)
setImageBitmap(bitmap);
}
};
Thread downLoadThread = null; @Override
public void setImageURI(final Uri uri) {
if(uri==null)return;
final String path = uri.toString();
Log.d(getClass().getSimpleName(), "image path=" + path);
if (uri.getScheme() !=null && uri.getScheme().startsWith("http")) {
StringBuilder folder = new StringBuilder(mCacheFolder); folder.append(uri.getPath());
int s = folder.indexOf("?");
if (s > -1) {
folder.delete(s, folder.length());
}
final File localPath = new File(folder.toString()); final String fileName = localPath.getName(); if (this.mCacheFolder == null) {
Log.w(getClass().getSimpleName(), "not set cache folder,image will not download");
return;
} downLoadThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Message msg = new Message(); Bundle data = new Bundle();
if (localPath.exists()) {
bitmap = getLoacalBitmap(localPath.getAbsolutePath());
if (bitmap != null)
msg.what = 1;
} else {
InputStream is = WebUtil.getStream(path);
bitmap = BitmapFactory.decodeStream(is);
String imgpath = saveFile(bitmap, localPath.getParent(), fileName);
if (imgpath != null) {
msg.what = 1;
}
} msg.setData(data); handler.sendMessage(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
});
downLoadThread.start();
} else {
super.setImageURI(uri);
}
} /**
* 加载本地图片 http://bbs.3gstdy.com
*
* @param url
* @return
*/
public static Bitmap getLoacalBitmap(String url) {
try {
FileInputStream fis = new FileInputStream(url);
return BitmapFactory.decodeStream(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
} /**
* 保存文件
*
* @param bm
* @param fileName
* @throws IOException
* @return String
*/
public String saveFile(Bitmap bm, String folder, String fileName) {
File dirFile = new File(folder + "/");
if (!dirFile.exists()) {
if (!dirFile.mkdirs()) {
Log.e(getClass().getSimpleName(), "create folder failed:" + dirFile);
}
} File myCaptureFile = new File(dirFile, fileName);
Log.d(getClass().getSimpleName(), myCaptureFile.getPath());
if(!myCaptureFile.exists()){
try {
myCaptureFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
BufferedOutputStream bos =null;
try {
bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
} catch (FileNotFoundException e) {
return null;
} finally{
if(bos !=null)
try {
bos.flush();
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return myCaptureFile.getAbsolutePath();
} public int getQuality() {
return quality;
} public void setQuality(int quality) {
this.quality = quality;
} @Override
protected void finalize() throws Throwable {
if(downLoadThread!=null)downLoadThread.interrupt();
super.finalize();
}
}