獲取參數的方法我有方法來調整圖像,我想從陣列參數,但它一直顯示錯誤說如何從陣列
incompatible types
found int
required android.graphics.drawable.Drawable
這是我的方法
public Drawable ResizeImage (int imgResize){
Display imgPost = getWindowManager().getDefaultDisplay();
double dvcWidth = imgPost.getWidth();
BitmapDrawable imgBD = (BitmapDrawable)this.getResources().getDrawable(imgResize);
double imgHeight = imgBD.getBitmap().getHeight();
double imgWidth = imgBD.getBitmap().getWidth();
double imgRatio = dvcWidth/imgWidth;
int newImgHeight = (int) (imgHeight*imgRatio);
Bitmap imgBmap = BitmapFactory.decodeResource(getResources(),imgResize);
Drawable imgDrawable = new BitmapDrawable(this.getResources(),getResizedBitmap(imgBmap,newImgHeight,(int) dvcWidth));
return imgDrawable;
}
我的數組
int[] imgDvc= new int[]{
ResizeImage(R.drawable.pc),
R.drawable.ps4,
R.drawable.xbone
}
,我打電話給我的陣列通過這裏
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<10;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("Dvc", Integer.toString(imgDvc[i]));
aList.add(hm);
}
String[] game= {"Dvc"};
我用它來填充listview,謝謝你的回答。
代碼中的哪行代表錯誤指的是? –
@MehmetKologlu this ResizeImage(R.drawable.pc)line。 – sh4man
哦,我現在看到它。你已經聲明瞭一個int數組,但你試圖在其中添加一個'Drawable'。你不能這樣做。 –