【发布时间】: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