0

I am extending ListActivity in one of my Activities but I need to extend one more Activity.

So, is there an alternative for extending ListView in Android?

I am using the ListView to display the data from database.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

First of all: Java does not support multiple inheritance.

After this, what I would to, is to rethink in the design: does it make sense to your class to be ListActivity and other Activity?

If yes, there are a couple of workarounds you can try:

  • Aggregation: make a class that takes those two activities as fields.

  • Interfaces.

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • Basically, I am asking how to use the methods of ListActivity by manually making an object of ListView – Sheena Gupta Apr 13 '15 at 10:59
  • I must see more of your code to understand what you need exactly... [check this link](http://www.vogella.com/tutorials/AndroidListView/article.html) hope it clarifies... ;) – Jordi Castilla Apr 13 '15 at 11:07
  • in the xml file in which I have used ListView, I have used something like this: android:id="@+id/android:list" How do I access it's id now? – Sheena Gupta Apr 13 '15 at 11:16
  • you can reference it by `ListView mListView = (ListView) findViewById(R.id.list);` then you can manipulate `mListView` as a normal Java object... But please, [check this answer](http://stackoverflow.com/questions/4355614/what-is-difference-between-id-androidlist-and-id-list), to know more about referencing id's. – Jordi Castilla Apr 13 '15 at 11:38