0

这是我的代码:

private void setWeatherDialogInfoAndIcons(){
    WeatherGoogle weather = WeatherGoogle.getInstance("istanbul");
    String iconsPath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/arla/images/hava/";
    String[] allData = weather.getCityData().split("<>");

    currentImage = (ImageView) customDialog.findViewById(R.id.imageViewcurrentWeatherImage );
    currentInfo  = (TextView) customDialog.findViewById( R.id.textViewCurrentInfo )  ;
    currentInfo.setText( allData[0] +"\n"+allData[1]+"\n"+allData[2]+"\n"+allData[3] );

    currentImage.setBackgroundResource(R.drawable.air);
    currentImage.setBackgroundDrawable( UiHelper.getDrawableFromSdcard(iconsPath + weather.getIconName(0)) );

    int j = 4;
    for (int i = 0; i < dayInfos.size() ; i++) {
        dayInfos.get(i).setText( allData[j] +"\nMin  : "+ allData[j+1] +"\nMaks: "+ allData[j+2] 
                + "\n" + allData[j+3]   );
        j+=4;
    }

}

我可以更改 textviews 的文本,但是当我想设置 imageviev(currentImage) 的背景时它不起作用,它显示对话框但Imageview中没有背景。

 currentImage.setBackgroundDrawable( UiHelper.getDrawableFromSdcard(iconsPath + weather.getIconName(0)) );

我确信我的方法getDrawableFromSdcard有效,因为我在代码中的其他地方使用了它最后我检查了 png 图标及其路径。那么可能是什么问题?

4

2 回答 2

0
currentImage.setBackgroundDrawable(getResources.getDrawable(R.drawable.air));

从 SD 卡:

Bitmap picture = BitmapFactory.decodeFile("file_path");
imageView.setImageBitmap(picture);

尝试一下。祝你好运!

于 2012-07-12T11:54:01.173 回答
-1

该方法setBackgroundDrawable(Drawable background)已弃用。你必须setBackground(Drawable)改用。请参阅参考资料

于 2012-07-12T11:51:43.957 回答