【问题标题】:How to extend class with two another classes?如何用另外两个类扩展类?
【发布时间】:2015-09-29 14:31:26
【问题描述】:

我想用另外两个类 Fragment 和 Activity 来扩展我的类。 我试过这个:

public class Frist extends Fragment , Activity 
{
      .....
      .....
}

但它不起作用。我该如何解决?

【问题讨论】:

标签: java android


【解决方案1】:

您不能扩展多个类。为什么不能在另一个类中扩展 Fragment?

【讨论】:

    【解决方案2】:

    你应该使用装饰器或组合模式

    【讨论】:

      【解决方案3】:

      Java 不支持多重继承
      片段和活动都是完全不同的东西。
      如果您想让 Activity 具有片段,那么在 android studio 中使用 Activity with Fragment 而不是 Blank activity 创建项目
      然后,android studio 将自动提供一些代码,其中包含片段和类以及 xml。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-10-05
        • 2012-01-06
        • 1970-01-01
        • 2013-06-18
        • 1970-01-01
        • 1970-01-01
        • 2013-07-18
        相关资源
        最近更新 更多