Change Background Image On User's Choice
Solution 1:
you cannot access the UI components which are not yet instantiated. Use Intents to pass information across activities (user's choice, or some custom flags or Strings) and use this "extra" information in the launched activity to change the background accordingly.
Read more about intents in the documentation for better understanding and examples.
Solution 2:
You cannot do this.. When you refer a layout file using findViewById()
, the android system looks for this in your current ContentView
only. (i.e the view which you have set using setContentView()
for the current activity). So obvioulsy the sytem will not be able find the resource you are specifying and hence you will get the NullPointerExeption only.
You have to maintain the reference to the backgrounds separately and use it in your other Activity when you actually pass on there.
Post a Comment for "Change Background Image On User's Choice"