So basically, I have an xml, which i want to reuse. The content is somewhat the same, only the background is different and a few adjustment too.. How can I go about to do this.. I have tried View.setBackGroundDrawable(R.drawable.sample); but it does not work. My app crash. I’ve placed my image inside one of the drawable folder though.
So basically, I have an xml, which i want to reuse. The content is
Share
You can try to assign an id for your layout on your xml so that on your java code, you can set a different layout for it.. Here is an example:
You can also create if statements before setting your background like:
If it is a RelativeLayout, then the same code applies, just change LinearLayout to RelativeLayout.
If this is not the problem, please post your LogCat.