Reputation: 281
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?
Upvotes: 0
Views: 676
Reputation: 8242
instead of using ListActivity and onListItemClick() use activity with listView added in view and ListView.setItemClickListener() ;
Upvotes: 1
Reputation: 5806
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?
Upvotes: 0
Reputation: 20760
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
Upvotes: 0
Reputation: 1500675
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.
Upvotes: 2