如何从 SupportMapFragment 获取片段扩展中的主要 Activity
How to get the main Activity in a fragment extedend from SupportMapFragment
我有:
MainActivity
fragment = new ListReportsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content, fragment).commit();
使用这个简单的代码,我调用了从 SupportMapFragment
扩展而来的片段
MyFragment
public class MyFragment extends SupportMapFragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
MainActivity main = (MainActivity) getParentFragment().getActivity()
}
}
但是 main
的值总是 null
。我如何发送或获取 MainActivity
?
改变
MainActivity main = (MainActivity) getParentFragment().getActivity();
和
MainActivity main = (MainActivity) getActivity();
我有: MainActivity
fragment = new ListReportsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content, fragment).commit();
使用这个简单的代码,我调用了从 SupportMapFragment
MyFragment
public class MyFragment extends SupportMapFragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
MainActivity main = (MainActivity) getParentFragment().getActivity()
}
}
但是 main
的值总是 null
。我如何发送或获取 MainActivity
?
改变
MainActivity main = (MainActivity) getParentFragment().getActivity();
和
MainActivity main = (MainActivity) getActivity();