While programming on Android, I end up writing a parent activity which is extended by several others. A bit like ListActivity
. My parent activity extends Activity
. if I intend to use a Map
or a List
, I can't use my parent activity as superclass - the child activity can only extend one activity obviously. As such I end up writing my parent activities with the same logic for Activity
, ListActivity
, MapActivity
and so forth.
What am I looking for is some sort of trait functionality/design pattern which would help in this case. Any suggestions?
I really dislike ListActivity
, MapActivity
etc. Basically they are activities which simply add a single view element at the cost of some flexibility. By adding a MapView
or ListView
to your XML appropriately, you end up with the same thing which can extend an Activity
derived superclass directly. So just don't use any of those SomethingActivity classes for the most part.
I've ended up having a base MyAbstractActivity extends Activity
that incorporates shared logic and a MyAbstractListActivity extends MyAbstractActivity
that mimics ListActivity
(inflates layout.R.id.list
, layout.R.id.empty
, etc.; not much going on there).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With