之前老是容易忘掉Fragment里面怎么findview,干脆写一篇博客,以后忘了回来再看
getSupportFragmentManager
Return the FragmentManager for interacting with fragments associated with this activity.
返回 FragmentManager 以与与此Activity关联的Fragment进行交互。
addToBackStack
Add this transaction to the back stack. This means that the transaction will be remembered after it is committed, and will reverse its operation when later popped off the stack.
将此事务添加到后台堆栈。这意味着事务在提交后将被记住,并在稍后弹出堆栈时反转其操作。
当您移除或替换一个片段并向返回栈添加事务时,系统会停止(而非销毁)移除的片段。 如果用户执行回退操作进行片段恢复,该片段将重新启动。 如果您不向返回栈添加事务,则系统会在您移除或替换片段时将其销毁。
Fragment与Activity进行交互:
Activity获得Fragment:调用supportFragmentManager的findFragmentById方法,可以在Activity中得到相应的Fragment实例,再通过as进行转换,如果想要Fragment中的view对象,那就findViewById
Fragment获得Activity:调用getActivity方法来得到和当前Fragment相关联的Activity实例
Fragment之间的通信:首先在一个Fragment中获得Activity实例,然后Activity实例获得另一个Fragment实例