문제

I have a function

 public void creacion_layout_items(R.drawable imagen_principal){
  LinearLayout _33_1_layout=(LinearLayout)findViewById(R.id.layout_principal);                               
        ImageView imagen=new ImageView(this);   
        LinearLayout.LayoutParams imagen_Params = new LinearLayout.LayoutParams(12,12);
        imagen.setLayoutParams(imagen_Params);
        imagen.setBackgroundResource(imagen_principal);
_33_1_layout.addView(imagen);
}

and I want to call the function

creacion_layout_items(R.drawable.all);

but does not work

도움이 되었습니까?

해결책

R.drawable.something is of int type. R.drawable is not type at all. So use

public void creacion_layout_items(int yourResDrawableId){
   ...
 imagen.setBackgroundResource(yourResDrawableId);
   ...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top