片段中的getMapAsync

时间:2016-05-21 21:39:17

标签: android android-fragments

我正在使用不同片段的Sliding Tabs。在地图片段中,我不能将嵌套片段用作XML。下面是Java代码和XMLfile。 我被卡在figure(); jCB = javaObjectEDT(javax.swing.JCheckBox('Green',0)); javacomponent(jCB, [20, 20, 60, 20], gcf); pause(0.1); while true plot(1); % just some random code display(jCB.isSelected()); end 方法所以如何使用getMapAsync()获取地图而没有任何异常?我真的很感谢你的合作。

Food Fragment Java:

getMapAsync

Food XML文件,

public class FoodFragment extends Fragment {

private SupportMapFragment mapfragment;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 View view= inflater.inflate(R.layout.food_layout, null);

mapfragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.maps_frame);
if (mapfragment == null) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    mapfragment = SupportMapFragment.newInstance();
    fragmentTransaction.replace(R.id.maps_frame,mapfragment).commit();
}
mapfragment.getMapAsync((OnMapReadyCallback) getActivity().getApplicationContext());

return view;

 }
}

1 个答案:

答案 0 :(得分:2)

您的ApplicationContext无法转换为OnMapReadyCallback您可以创建OnMapReadyCallback()的新实例作为匿名类,而不像您可能正在搜索的那样

  mapfragment.getMapAsync(new OnMapReadyCallback() {
        @Override public void onMapReady(GoogleMap googleMap) {
            if (googleMap != null) {
               // your additional codes goes here
               .....
            }
   }

如果需要,您也可以参考this example