android - How to receive data from Dialog Fragment in another fragment's setOnMapLongClickListener listener
问题描述
So this is my public View onCreateView method. I want to open dialog window when user long clicks on map, then take data from the dialog and then set .tittle according to data user inputted into the dialog. I tried doing it with interface but it would not have the data when I need it. getInput() is where I want to receive the data from Dialog fragment.
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latLng) {
//FragmentManager fm = getActivity().getSupportFragmentManager();
DialogMap dial = new DialogMap();
dial.setTargetFragment(MapFragment.this, 1);
dial.show(getFragmentManager(), "Add a catch");
mMap.addMarker(new MarkerOptions()
.position(latLng)
.title(getinput())
.snippet("Your marker snippet")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.fish_icon_map)));
This is my dialog's fragment.
解决方案
您错过了 DialogMap 中对话侦听器的初始化。
公共 onDialogOk 对话框。(你必须在使用前初始化它)
dialog = (onDialogOk)getTargetFragment()
所以在 onCreateView() 里面,你可以初始化它。
推荐阅读
- reactjs - React - 在 ssr 之前获取一些数据并在客户端获取一些数据
- flutter - 在颤振中使用 SharedPreferences 时出错
- python - 如何在 django 中一次创建多个具有不同值的对象?
- python - 如何在 roslibpy 上订阅字符串数据?
- python - Tkinter Key Bind 和 Entry 重叠
- specflow - 如何使用编程忽略规范流测试
- .net-core - .Net Core 3.1 自包含应用程序可以在 Windows 2008 上运行吗?
- web-config - Blazor - 如何使用 brotli 压缩
- amazon-web-services - 从 AWS ECS Fargate 访问 AWS RDS 的最佳方式
- ansible - regex_replace 由 jinja 模板中的 var 内容替换