How to add multiple implementations after extending the AppCompatActivity?
Why am I getting this error? Please correct this piece of code.
public class MainActivity extends AppCompatActivity
implements PopupMenu.OnMenuItemClickListener
implements NavigationView.OnNavigationItemSelectedListener{
Change it to
public class MainActivity extends AppCompatActivity
implements PopupMenu.OnMenuItemClickListener, NavigationView.OnNavigationItemSelectedListener{
You should read this too.
You shouldn't use implements twice to do so, just use it like this:
public class MainActivity extends AppCompatActivity
implements firstImplement, secondImplement {}
Related
I am looking for a way to add a base class to a mosby MVPActivity. Let me explain what i need.
Usually when using mosby we would declare an activity like this:
public class LoginActivity extends MVPActivity<LoginView, LoginPresenter> {
//...
}
but i would like to add a base class so that i can do the calls like this:
public class LoginActivity extends BaseActivity<LoginView, LoginPresenter> {
//...
}
and then BaseActivity would be like this :
abstract class BaseActivity<T, P> extends MvpActivity<T extends MvpView, P> {
}
but this is not working as the IDE at compile time has an error saying that "extends MvpView" has unexpected bounds.
So how can i add a base class to a mosby MVPActivity ?
You have to apply the generic parameters with your extended class definition and define it with the extension.
abstract class BaseActivity<V extends MvpView, P extends MvpPresenter<V>>
extends MvpActivity<V, P> { }
Can i use the implements and the extends at the same time? Because I need to inherit something on the other class while i used implements on the same class.
public class DetailActivity extends AppCompatActivity
implementsView.OnClickListener "extends ListActivity"
How can it be like that?
Yes, you can. But you need to declare extends before implements:
public class DetailActivity extends AppCompatActivity implements Interface1, Interface2 {
// ...
}
Any number of interfaces can be implemented, if more than one then each needs to be separated with a comma.
You can only extend one class but you implements multiple interfaces as your need.
class Human extends Monkey implements BasicAnimals, xyz
in this way you can extend a class as well as implement interfaces.
I want to create a composite in GWT that require a class which extends a class and implements an interface. Psudo code as below (it does not work apparently):
class GridRow<T extends Widget implements HasText> extends Composite{
//more codes here
}
That's written as:
class GridRow<T extends Widget & HasText> extends Composite {
// ...
}
You can have [class or interface]( & [interface])* (in pseudo regex language).
I have Scala class and I would like to extend one of the generic classes of JavaFX to create my custom contro
public abstract class SkinBase <C extends Control, B extends BehaviorBase <C>>
extends StackPane
implements Skin <C>
but I can't. example:
import javafx.scene.control.Control
class MyControl extends Control {
}
import com.sun.javafx.scene.control.skin.SkinBase
class MyControlSkin extends SkinBase[MyControl,MyControlBehavior] {
}
import com.sun.javafx.scene.control.behavior.BehaviorBase
class MyControlBehavior extends BehaviorBase[MyControl] {
}
Any suggestions how can I do that?
This works for me:
class MyControlBehavior(myControl: MyControl) extends BehaviorBase[MyControl](myControl)
I need to derive from the following class:
public abstract class MyTool<VIEW extends MyView>
implements LookupListener, MouseListener, MouseMotionListener, KeyListener {}
The following does not work:
public abstract class MySubTool<VIEW> extends MyTool<VIEW> {}
Thanks !
The compiler in MySubTool as no way of knowing that VIEW in MySubTool is a subclass of MyView, you have to specify it again:
public abstract class MySubTool<VIEW extends MyView> extends MyTool<VIEW> {}
This should:
public abstract class MySubTool<VIEW extends MyView> extends MyTool<VIEW> {}