2017-08-21 19 views
0

水平片段我做了什麼刪除高達「N」中的Android

所有片段添加一個在另一個之上,並添加到後退堆棧也

MainActivity - - - >Fragment_1 - >Fragment_2 - >Fragment_3 - >Fragment_4 - >Fragment_5 ------這可以去,直到片段N-Numbers

我所試圖做的

Asume我在Fragment_5,然後我按下一個按鈕,我應該能夠通過刪除片段一路穿越回Fragment_2高達該水平

如何實現這一點;

回答

0

你可以試試這個方法: fragmentManager.popBackStack(「The fragment of the fragment」,0);

的方法的描述:

/** 
* Pop the last fragment transition from the manager's fragment 
* back stack. If there is nothing to pop, false is returned. 
* This function is asynchronous -- it enqueues the 
* request to pop, but the action will not be performed until the application 
* returns to its event loop. 
* 
* @param name If non-null, this is the name of a previous back state 
* to look for; if found, all states up to that state will be popped. The 
* {@link #POP_BACK_STACK_INCLUSIVE} flag can be used to control whether 
* the named state itself is popped. If null, only the top state is popped. 
* @param flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}. 
*/