2016-11-06 162 views

回答

0

您可以使用Life Cycle了點。你所要做的就是創建一個通信接口。

interface RemoveItemSignal{ 
    void onRemove(); 
} 

然後註冊一個監聽器。

Signal<RemoveItemSignal> signal = SignalBag.Inject(RemoveItemSignal.class); 
signal.addListener(this); // Your listener that implements RemoveItemSignal 

從你的片段,你可以派遣這個信號是這樣的:

Signal<RemoveItemSignal> signal = SignalBag.Inject(RemoveItemSignal.class); 
signal.dispatcher.onRemove(); 
1

您是否閱讀過文檔communicating with other fragments? 它建議在BottomSheetFragment內部創建偵聽器接口,該接口將負責來自它的操作。比你activity應該實現此類似這樣的

public static class MainActivity extends Activity 
    implements BottomSheetFragment.OnActionSelectedListener{ 
... 

public void onActionSelected(int position) { 
    // The user did some action from the BottomSheetFragment 
    // Do something here to remove item from the RecyclerView 
} 
}