Issue
Is there any way I can check if a certain layout ID exists before using it with setContentView(R.layout.mylayoutid)?
Something like:
if(layout_exists("mylayoutid"))
setContentView(R.layout.mylayoutid);
else
setContentView(R.layout.defaultlayout);
couldn't find anything in the developer docs.
Thanks!
Solution
Yes, there is.
int layoutId = getContext().getResources().getIdentifier("mylayoutid","layout", getContext().getPackageName());
if (layoutId == 0){
// this layout doesn't exist
} else {
setContentView(layoutId);
}
Answered By - sha256
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.