简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM