I am switching gears from iOS to Android and I was wondering about how you re-use your view configuration in Android. In iOS I would typically create a BaseViewController that handled how my app would be “themed” and configured some common view components I wanted to be available everywhere and always (or with conditionals). I would then subclass BaseViewController to suit my view-specific needs. This may not be the ideal way to handle this sort of thing but it worked for me.
In Android I am not sure what I am supposed to do.
There appear to be far more options available for view configuration; I know that you can, like iOS, create views by inflating from XML layout files OR by creating them programatically. I also know that since Java offers inheritance, you could extend the Activity class. So I see a few paths: you could create a base_view.xml file and include it in future layout files, but I see this as being kind of hacky for some reason. You could also create that base_view.xml file, use it in a non-implementable BaseActivity class, and subclass BaseActivity to an implementable and activity-specific version. Or, you could do it programatically in BaseActivity and subclass. I am also vaguely aware of “theme” options in Android that may simplify some of this.
I am almost certain I am going about this in the wrong way and that there are thousands of people who have had to deal with re-using some view configuration before, so all help is appreciated.
There are many different things you may want to re-use. You are not being as specific as we would like to. For instance, these are just some of the things you may want to re-use:
android:themeattribute in the application tag of yourAndroidManifest.xmlfile.BaseActvitiywhich handles and configures the actionbar (take a look at the iosched app source code). However, what I recommend in these cases is stick to libraries like ActionBarSherlock which will make things easier and nicer.startSearchmethod. In those cases inheritance is encouraged.Context). For this case, and in general, I highly recommend you to stick to the support library so that you can use the Fragments API; I know it could be somehow difficult to use at first, but it definitely worths the effort.If your needs are more specific do not hesitate to comment so that I can try to advice how to proceed.