我正在观看 thenewboston 关于 fragment 的教程,我遇到了这行代码..
@Override
public void sendtex(String top, String bottom) {
BottomFregment_class bottomFregment = (BottomFregment_class) getSupportFragmentManager().findFragmentById(R.id.Main);
bottomFregment.finale(top,bottom);
}
这是通过从另一个 fragment 获取文本来更改 TextView!和“sendtext 是该 fragment 的实现方法”
我替换了
BottomFregment_class bottomFregment = (BottomFregment_class) getSupportFragmentManager().findFragmentById(R.id.Main);
bottomFregment.finale(top,bottom);
与
BottomFregment_class bottomFregmentClass = new BottomFregment_class();
bottomFregmentClass.finale(top,bottom);
一切正常!
我想知道这两个代码有什么区别吗? 或者这会导致任何性能问题吗?
最佳答案
在第一个中,您获取一个现有 fragment ,其中可能包含一些数据,在另一个 fragment 中,您创建一个空 fragment 。
关于java - Android,这些代码有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44776526/