2016-11-06 117 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 
} 
}