我想显示来自服务器的图像。实际上,我需要显示一个段落以及一个图像。我为此选择了一个列表视图。目前我正在显示该段落,但是当我尝试显示图像时它不起作用。帮我解决这个...
我的代码:
private class ListAdapter extends ArrayAdapter<UserBO> {
--
--
--
-- public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
try {
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.list_item, null);
// --CloneChangeRequired(list_item)
}
final UserBO listItem = mList.get(position); // --CloneChangeRequired
if (listItem != null) {
--
--
--
--
imageUrl = "http://server.com//folder/"+ array.get(0);
((TextView) view.findViewById(R.id.description))
.setText(listItem.getdesc()));
downloadFile(imageUrl);
----
--
}
}
}
}
void downloadFile(String fileUrl) {
URL myFileUrl = null;
try {
myFileUrl = new URL(fileUrl);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}