【发布时间】:2015-09-25 09:55:49
【问题描述】:
我有一个看起来像这样的应用:
这是一个 recyclerview,recyclerview 中有片段。
recyclerview xml 是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:id="@+id/main_recyclerview_holder">
<android.support.v7.widget.RecyclerView
android:id="@+id/main_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
位于名为 backgroundRlMaps 的 recyclerview 的每一行中的片段布局 xml 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/backgroundRlMaps"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BACK"/>
<other views...>
</RelativeLayout>
您看到的视图首先覆盖一个带有一个按钮的简单视图,一旦用户单击该按钮,该视图就会显示以显示显示地图的 backgroundRlMaps 视图。例如,recyclerview 中的每个项目都将是一个不同的国家(中国、印度、巴基斯坦等),每次单击地图按钮时,片段都会显示适用的地图。
我已经为地图按钮粘贴了以下逻辑:
((ViewHolder) holder).mapButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//bringing the fragment container called backgroundRlMaps to the front
((ViewHolder) holder).backgroundRlMaps.bringToFront();
//Dealing with maps here
//A new supportMapFragment is formed every time
SupportMapFragment mapFragment = SupportMapFragment.newInstance();
mapFragment.getMapAsync(RecyclerViewAdapter.this);
//Adding the map to the relativeLayout fragment container
f.getChildFragmentManager().beginTransaction().add(((ViewHolder) holder).backgroundRlMaps.getId(), mapFragment, String.valueOf(position)).commit();
f.getChildFragmentManager().executePendingTransactions();
}
}
但是,每次单击地图按钮时,只有顶部片段 backgroundRlMaps 显示地图,并且每次单击其他国家/地区的地图按钮时,我都可以看到顶部片段刷新其视图。 与屏幕显示一样,另外两个仍然没有显示任何内容。
有没有办法让它正常工作?
我怀疑由于 backgroundRlMaps 在我的所有片段中都是重复的,所以当我要求 childFragmentManager 添加到 SupportMapFragment 时,它会选择具有该布局引用的第一个片段来添加 supportMapFragment。
【问题讨论】:
标签: android google-maps android-fragments supportmapfragment