为什么日志行在这里输出“true”?我刚刚添加了一个带有标签“ID”的 fragment !
FragmentTransaction ftrans = getSupportFragmentManager().beginTransaction();
ftrans.add(0, new MyFrag(), "ID");
ftrans.commit();
Fragment frag = getSupportFragmentManager().findFragmentByTag("ID");
Log.i("", "Fragment is null? " + (frag == null));
提交有延迟吗?如果是这样,提交完成时我可以监听任何事件吗?
最佳答案
public abstract int commit ()
Schedules a commit of this transaction. The commit does not happen immediately; it will be scheduled as work on the main thread to be done the next time that thread is ready.
您可以尝试在 commit() 之后、查找标记之前添加fragmentManager.executePendingTransactions()。
关于android - 为什么 fragment 管理器在这里返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16373679/