Android 如果我更改活动,然后返回,SwipeRefreshLayout将不再工作
这是我的xml:Android 如果我更改活动,然后返回,SwipeRefreshLayout将不再工作,android,android-recyclerview,refresh,swipe,swiperefreshlayout,Android,Android Recyclerview,Refresh,Swipe,Swiperefreshlayout,这是我的xml: <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout" android:layout_below="@id/id_bar" android:layout_marginBottom="0.5dp" android:background="@color/blue" android:layout_width="match_p
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_below="@id/id_bar"
android:layout_marginBottom="0.5dp"
android:background="@color/blue"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:dividerHeight="0dp"
android:layout_gravity="top"
android:divider="@null"
android:background="@color/yellow"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<com.bartoszlipinski.recyclerviewheader2.RecyclerViewHeader
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="70dp"
android:visibility="gone"
android:layout_gravity="center_horizontal|top">
<include
android:id="@+id/header_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_top_green"
layout="@layout/header_profile"/>
</com.bartoszlipinski.recyclerviewheader2.RecyclerViewHeader>
<RelativeLayout
android:id="@+id/placeholderContainer"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:layout_height="match_parent">
<ImageView
android:id="@+id/placeholderPic"
android:layout_alignParentTop="true"
android:layout_marginTop="100dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pin_newtrips"/>
<TextView
android:id="@+id/placeholderText"
android:layout_below="@id/placeholderPic"
android:padding="10dp"
android:textSize="28dp"
android:textColor="@color/gray32"
android:text="@string/home.status.heading.setup"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/placeholderAddItems"
android:layout_marginTop="10dp"
android:layout_below="@id/placeholderText"
android:layout_width="match_parent"
android:layout_height="wrap_content"></RelativeLayout>
</RelativeLayout>
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
这是我的听众:
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// Refresh items
if(timeLineAdapter!= null)
timeLineAdapter.setLastAnimatedPosition(0);
refresh(false);
}
});
我把它称为简历,这样,如果我再回来,它就会起作用。
现在它开始工作了,如果我按home键回来,它就工作了。
如果我将我的活动更改为另一个活动,然后重新开始,它就不再起作用了。如何解决这个问题
编辑:如您所见,SwiperFreshLayout的主要子级是一个FrameLayout,其中包含RecyclerView、my RecyclerViewHeader和列表的占位符(在这里,因为向下滑动占位符也应滑动以刷新)。
我在这两个视图之间添加了一个ScrollView,现在可以使用滑动刷新。但是,将recyclerview放在ScrollView中会破坏我的recyclerview。我可以向下滚动,但不能向上滚动。还有其他想法吗?当我检查列表中是否有要显示的对象时,代码中有timelineList.setVisibility(View.Invisible)。 我将其删除,并设置为:
if(timeLineAdapter != null) {
timeLineAdapter.clearItems();
timeLineAdapter.notifyDataSetChanged();
}
现在列表没有设置为不可见。
我在SwipeRefreshLayout中添加了我的占位符和列表,认为这两个都可以,但实际上它只在列表中起作用,所以如果列表不存在,刷新的拉动也就不存在了当我检查列表中是否有要显示的对象时,我在代码中有timelineList.setVisibility(View.Invisible)。 我将其删除,并设置为:
if(timeLineAdapter != null) {
timeLineAdapter.clearItems();
timeLineAdapter.notifyDataSetChanged();
}
现在列表没有设置为不可见。
我在SwipeRefreshLayout中添加了占位符和列表,以为这两个都可以,但实际上它只在列表上起作用,所以如果列表消失了,刷新的拉动也就消失了