ANDROID-如何将位图设置为simpleadapter(已关闭)
我正在开发我的android应用程序。我一直在研究和尝试各种不同的方法,如何从我的服务器url检索图像,并使用ANDROID-如何将位图设置为simpleadapter(已关闭),android,adapter,simpleadapter,Android,Adapter,Simpleadapter,我正在开发我的android应用程序。我一直在研究和尝试各种不同的方法,如何从我的服务器url检索图像,并使用simpledapter将其显示到我的listview 下载图像代码 public Bitmap download(final String image) { URL myFileUrl = null; try { myFileUrl = new URL("http://SERVER URL/images/"+image); HttpUR
simpledapter
将其显示到我的listview
下载图像代码
public Bitmap download(final String image)
{
URL myFileUrl = null;
try {
myFileUrl = new URL("http://SERVER URL/images/"+image);
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
//int length = conn.getContentLength();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
} catch (MalformedURLException e) {
// imageLoadedHandler.sendEmptyMessage(FAILED);
} catch (IOException e) {
// imageLoadedHandler.sendEmptyMessage(FAILED);
}
return bmImg;
}
将下载的图像放入HASHMAP
// IMAGE HASHMAP
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(TAG_PHOTO, download(c.getString(TAG_PHOTO)));
applicantsList.add(map);
在尝试了上述方法(我认为这是我研究中最接近的答案)之后,图像仍然没有显示在我的应用程序中。我需要帮助!提前谢谢 您需要创建一个扩展BaseAdapter的类,并实现getView()方法以实现这一点。
adapter = new SimpleAdapter(
SignUpApplicantActivity.this, applicantsList,
R.layout.list_applicant, new String[] {
TAG_UID, TAG_NAME, TAG_OVERALL,
TAG_APPLY_DATETIME, TAG_PHOTO},
new int[] { R.id.applicantUid,
R.id.applicantName,
R.id.applicantOverall,
R.id.apply_datetime, R.id.list_image});
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data,String textRepresentation)
{
if((view instanceof ImageView) & (data instanceof Bitmap))
{
ImageView iv = (ImageView) view;
Bitmap bm = (Bitmap) data;
iv.setImageBitmap(bm);
return true;
}
return false;
}
});
// updating listView
setListAdapter(adapter);