Breaking News
Loading...

How TO Get Image using Name from Raw or drawable folder

7:51 PM
In some situtaion we have to get image from drawable or raw folder using image name instead if generated id

// Image View Object

mIv = (ImageView) findViewById(R.id.xidIma);
// create context Object for  to Fetch  image from resourse 
Context mContext=getApplicationContext();


// getResources().getIdentifier("image_name","res_folder_name", package_name);


// find out below example 
    int i = mContext.getResources().getIdentifier("ic_launcher","raw", mContext.getPackageName());


// now we will get contsant id for that image
mIv.setBackgroundResource(i);





0 komentar:

Post a Comment

 
Toggle Footer