mhplur
mhplur

Reputation: 218

load R.drawable in function android

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

Upvotes: 0

Views: 269

Answers (1)

michal.luszczuk
michal.luszczuk

Reputation: 2903

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);
   ...
}

Upvotes: 1

Related Questions