1

My project consists of couple of activity and ListActivity items, there is some common piece of code(Navigation bar and some other codes) which needs to be done on both type of activity.

Is there a way I extend the activity and write my piece of code, and let ListActivity also inherent that code ?

right now I am copying the same piece of code in two classes , one is Activity extended and other is ListActivity extended

Shahzad
  • 21
  • 5

3 Answers3

1

You could also have the common code in a class CSuperCommon, and have each of your Activities contain an inner class that inherits from CSuperCommon. Some initialization will need to be done such as setting the parent view, context, etc.

Rajath
  • 11,787
  • 7
  • 48
  • 62
0

There is no real multi inheritance in java (and so in android) but it is possible to simulate it: http://www.javaworld.com/javaworld/jw-10-2005/jw-1024-multiple.html.

Here is another answer from stackoverflow: How do Java Interfaces simulate multiple inheritance?

Community
  • 1
  • 1
Moss
  • 6,002
  • 1
  • 35
  • 40
0

Have both extend a Base Activity class (which will have your common code) and implement a list view in one of them. Implementing a list view is very easy!

Azlam
  • 2,052
  • 3
  • 24
  • 28
  • Can you please elaborate on implementation of it – Shahzad Apr 07 '11 at 13:13
  • What I was saying was have one of the activity's view contain a ListView (like any other view), then get it assigned to an object, then set the adapter and onClickListeners, so you now have an activity with a list view, you dont need to extend ListActivity for this – Azlam Apr 07 '11 at 17:22