Jun 5, 2012

How TO Get Image using Name from Raw or drawable folder

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

No comments:

Post a Comment