Activity 传值给 Fragment
Activity使用Bundle 传值:
Bundle bundle = new Bundle();
bundle.putString("value", "Hello world");
fragment.setArguments(bundle);
Fragment获取值:
Bundle bundle = this.getArguments();
String value = bundle.getString("value");
Fragment 传值给Activity
创建一个接口:
public interface ICallback{
void getCallbackData(String data);
}
public void sendData(ICallback callback)
{
callback.getCallbackData("这里写要回调的内容");
}
Activity 实现这个ICallback 接口:
fragment.sendData(new ICallback(){
@Override
public void getCallbackData(String data){
Log.i("Data","----->"+ data);
}
});