android - How to fetch a R id in Java using a variable name -
imageview test = (imageview) findviewbyid(r.id.a1);
gets me imageview
instead of a1 use string variable fetch series of ids
i have tried
method pmethod = class.getdeclaredmethod("(imageview) findviewbyid(id.r." + dest.tostring());
as suggusted in question : how call java method using variable name?
however error
non-static method getdeclaredmethod cannot referenced static context
any way fix this?
my latest attempt :
string ps = "p"+ dest.tostring(); string ss = "s"+ dest.tostring(); int piecelayertier = getresources().getidentifier(ps,"id","com.donthaveawebsite.mhy.ocfix"); int selectorlayertier = getresources().getidentifier(ss,"id","com.donthaveawebsite.mhy.ocfix"); imageview test =(imageview)findviewbyid(piecelayertier); spot.tieappearance((imageview)findviewbyid(piecelayertier)); spot.tieselector((imageview)findviewbyid(selectorlayertier));
i think not correct way id.
you can try following id using string variable :
int id = getresources().getidentifier("<string id>","id","<package name>"); imageview test =(imageview)findviewbyid(id); you might need use this reference :
int id = this.getresources().getidentifier("<string id>","id", getpackagename());
Comments
Post a Comment