嵌套SupportMapFragment内Recyclerview
问题描述:
我有一个应用程序,看起来是这样的:嵌套SupportMapFragment内Recyclerview
这是一个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视图。例如,回收者视图中的每个项目将是不同的国家(中国,印度,巴基斯坦等),每次单击地图按钮时,该片段将显示适用的地图。
我已经粘贴了以下逻辑为mapbutton:
((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。
我不知道,将工作作为从recyclerview基本视图只想改变到ListView,但碎片还是要在列表视图等的每一行我会回到同样的问题。 – Simon
@Simon我的答案中的主要事情是不可能将Fragment作为ListView项目! – Oleksandr