我有主要的活动和一个片段。在这个片段中,我使用了Google。我想知道,如何用java将map片段的实例传递给主活动。因为我想把这张地图变成主要的活动。
我有这门课的主要活动
public static class HomeFragment extends Fragment {
private static View view;
public HomeFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(view != null)
{
ViewGroup parent = (ViewGroup) view.getParent();
if(parent != null)
{
parent.removeView(view);
}
}
try
{
view = inflater.inflate(R.layout.fragment_home, container, false);
}
catch(InflateException e){
// map is already there, just return view as it is
}
return view;
}
}fragment_home.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
tools:context="com.gaurav.googlemap.HomeMap" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" >
</fragment>
</RelativeLayout>我想在主活动中实例化这一行下面的地图,
view = inflater.inflate(R.layout.fragment_home, container, false);谢谢。
发布于 2015-02-18 03:20:49
您可以添加任何方法,例如
public void getFragment(Fragment fragment){
}在MainActivty和片段中
您可以使用以下代码调用此方法..。
((MainActivity)getActivity()).getFragment(this);我希望它能帮到你.
https://stackoverflow.com/questions/28575041
复制相似问题