Pregunta

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

¿Fue útil?

Solución

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);
   ...
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top