视图寻呼机仅在第一时间为空
问题描述:
我有一个包含回收视图的片段,并且在每个项目上按下另一个片段显示持有查看寻呼机,该寻呼寻呼机显示每个刷卡片段。当我按下回收视图项目后首次进入片段时,寻呼机不可见。 第二次,其余时间的数据如预期显示。视图寻呼机仅在第一时间为空
代码:
主要碎片持有观点寻呼机:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lineItems"
style="@style/TitleTextView"/>
<android.support.v4.view.ViewPager
android:id="@+id/CardTablepager"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"/>
</LinearLayout>
内容的片段(查看传呼机挥笔这个片段):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/poMainlayout">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardViewStyle"
android:layout_margin="8dp"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/poLineItemsTable"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideInset"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
我看了几个帖子没有帮助:Android Viewpager display wrong data on first load
我也尝试使主要碎片的适配器无效nt没有帮助:
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
viewPager.getAdapter().notifyDataSetChanged();
}
有什么想法吗?
答
只是通知你的适配器onCreateView不onViewCreated
@Override
public void onCreateView(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
viewPager.getAdapter().notifyDataSetChanged();
}
答
尝试改变你的viewpager下面,
<android.support.v4.view.ViewPager
android:id="@+id/CardTablepager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="600dp"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
而对于RecyclerView
集以下属性:
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
+0
好的尝试,但仍然是相同的行为。 – BoazGarty
你没有把'ScrollView'里面的Recyclerview'实现'ScrollingView'&'NestedScrollingChild' – eLemEnt
我想用横向和纵向滚动创建回收视图,而不是问题,所以我更新了问题。 – BoazGarty