Breaking News

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

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Toggle Footer