【问题标题】:Android , What is the difference between these codes?Android ,这些代码有什么区别?
【发布时间】:2017-06-27 09:19:35
【问题描述】:

我在看新波士顿关于片段的教程,我遇到了这行代码..

    @Override
    public void sendtex(String top, String bottom) {


      BottomFregment_class bottomFregment = (BottomFregment_class) getSupportFragmentManager().findFragmentById(R.id.Main);
      bottomFregment.finale(top,bottom);
    }

这是通过从另一个片段获取文本来更改 TextView!和“sendtext 是从那个片段实现的方法”

我换了

BottomFregment_class bottomFregment = (BottomFregment_class) getSupportFragmentManager().findFragmentById(R.id.Main);
      bottomFregment.finale(top,bottom);

 BottomFregment_class bottomFregmentClass = new BottomFregment_class();
    bottomFregmentClass.finale(top,bottom);

一切正常!

我想知道这两个代码之间有什么区别吗? 或者这会导致任何性能问题吗?

【问题讨论】:

  • 第一种情况是获取 xml 中声明的片段的引用。但在第二种情况下,您正在创建一个新片段,并且您必须将其动态绑定到任何其他父级。
  • 不同之处在于,在原始代码中,现有片段是通过片段管理器帮助检索的,而在您的情况下,您正在创建新的片段实例

标签: java android android-fragments


【解决方案1】:

首先,您获取一个现有片段,其中可能包含一些数据,然后在另一个片段上创建一个空片段。

【讨论】:

    猜你喜欢
    • 2012-09-27
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 2011-11-22
    • 2013-05-13
    相关资源
    最近更新 更多