0

Hi to all. I have this problem, I created an activity (this activity is called Activity1).
Activity1 runs a second activity (this activity is called Activity2), public class Activity2 extends Activity1 { }
Now I want to implement the function onListItemClick(), but to use this function, I must use extends ListActivity, but if I write public class Activity2 extends Activity1 extends ListActivity { }, I have this error:

Syntax error on token "extends", implements expected

Where I am wrong?

Alberto Solano
  • 7,972
  • 3
  • 38
  • 61
Ant
  • 281
  • 1
  • 4
  • 19

4 Answers4

2

You can't extend two classes in Java. It's not clear why you believe you need to extend either or both of Activity1 and ListActivity, but you won't be able to do so. (Of course if Activity1 already extended ListActivity, you'd just have to extend Activity1...)

You should consider why you want to extend Activity1, and potentially use composition instead - make both Activity1 and Activity2 use an instance of the same third type which contains information and logic common to both.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
1

instead of using ListActivity and onListItemClick() use activity with listView added in view and ListView.setItemClickListener() ;

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
0

In java you can not extend two classes. If you want you, can implement multiple interfaces and extend a single class by using class A extends B implements C,D

Thirler
  • 20,239
  • 14
  • 63
  • 92
0

You can not extend from two classes in java. Refer to following discussion which are almost similar: How to inherit from multiple base classes in Java?

Community
  • 1
  • 1
Prashant Lakhlani
  • 5,758
  • 5
  • 25
  • 39