【发布时间】:2018-11-20 18:45:55
【问题描述】:
我正在从 URL 下载图像并显示在图像视图上,但问题是如果图像名称以数字开头,则无法显示。
private class DownloadFilesTask extends AsyncTask<String, Void, Bitmap> {
protected Bitmap doInBackground(String... urls) {
try {
URL url = new URL(urls[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(Bitmap result) {
//loading.dismiss();
String image_name = result.toString();
if( Character.isDigit(image_name.charAt(0))){
}
imageView.setImageBitmap(result);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
}
}
【问题讨论】:
-
先显示你的代码然后给你解决方案。
-
只有你的代码才能告诉问题的实际解决方案
-
我已经编辑了这个问题。代码已添加
-
我想更改此代码块内的图像名称。 if( Character.isDigit(image_name.charAt(0))){ }
-
它不应该依赖于图像名称。问题可能出在其他地方