Java Switch布局工作不正常

Java Switch布局工作不正常,java,android,swiperefreshlayout,Java,Android,Swiperefreshlayout,我正在尝试在我的应用程序中实现SwipeRefreshLayout。该应用程序的功能运行良好。SwipeRefreshLayout也可以正常工作,直到它运行时,用户再次关闭,然后发生的是SwipeRefreshLayout关闭并开始出现错误行为。我注意到无论用户下拉多少次,onRefresh都会被调用一次。对可能出现的问题有什么建议吗?我上传了一段关于这个问题的youtube视频 这是该片段的xml(我的应用程序使用片段): 我可以用ListView而不是RecycleView来解决我的问题。由

我正在尝试在我的应用程序中实现SwipeRefreshLayout。该应用程序的功能运行良好。SwipeRefreshLayout也可以正常工作,直到它运行时,用户再次关闭,然后发生的是SwipeRefreshLayout关闭并开始出现错误行为。我注意到无论用户下拉多少次,onRefresh都会被调用一次。对可能出现的问题有什么建议吗?我上传了一段关于这个问题的youtube视频

这是该片段的xml(我的应用程序使用片段):


我可以用ListView而不是RecycleView来解决我的问题。由于某些原因,SwiderFreshLayout不能很好地与RecycleView配合使用。 当前\u片段代码:


<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:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:background="@drawable/bg_gradient"
            tools:context="koemdzhiev.com.stormy.ui.HourlyForecastActivity">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/hourly_swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:id="@+id/recyclerView"/>

</android.support.v4.widget.SwipeRefreshLayout>
    public class Hourly_forecast_fragment extends Fragment {
    private Hour[] mHours;
    private MainActivity mActivity;
    @InjectView(R.id.hourly_swipe_refresh_layout)
    SwipeRefreshLayout mSwipeRefreshLayout;
    RecyclerView.LayoutManager layoutManager;
    //inject the RecyclerView as member variable
    @InjectView(R.id.recyclerView)
    RecyclerView mRecyclerView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivity = ((MainActivity) getActivity());


    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v =inflater.inflate(R.layout.hourly_forecast_fragment,container,false);
        ButterKnife.inject(this, v);
        layoutManager = new LinearLayoutManager(mActivity);
        mRecyclerView.setLayoutManager(layoutManager);
        mSwipeRefreshLayout.setColorSchemeResources(R.color.green,R.color.blue,R.color.orange);
        if (mRecyclerView != null)
            mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    //if there is internet and if the mSwipeRefreshLayout in the current and daily fragments are not already running...
                    if (mActivity.isNetworkAvailable()) {
                        if (!mActivity.mCurrent_forecast_fragment.mSwipeRefreshLayout.isRefreshing() && !mActivity.mDaily_forecast_fragment.mSwipeRefreshLayout.isRefreshing()) {
                            mActivity.getLocation();
                        }else{
                            mSwipeRefreshLayout.setRefreshing(false);
                            Toast.makeText(mActivity, "currently refreshing...", Toast.LENGTH_LONG).show();
                        }
                    } else {
                        Toast.makeText(mActivity, "No Internet Connection!", Toast.LENGTH_LONG).show();
                        mSwipeRefreshLayout.setRefreshing(false);
                    }
                }
            });
        Log.e("Forecast_fragment", "onCreateView");
        return v;
    }

    public void setUpHourlyFragment(){
        if (mActivity.mForecast != null) {
//            Toast.makeText(mActivity, getString(R.string.network_unavailable_message), Toast.LENGTH_LONG).show();
            Hour[] hourlyForecast = mActivity.mForecast.getHourlyForecast();
            mHours = Arrays.copyOf(hourlyForecast, hourlyForecast.length, Hour[].class);

            HourAdapter adapter = new HourAdapter(mActivity, mHours);
            mRecyclerView.setAdapter(adapter);
            mRecyclerView.setHasFixedSize(true);
            layoutManager = new LinearLayoutManager(mActivity);
            mRecyclerView.setLayoutManager(layoutManager);
            //if dealing with fixed size data, it is recommended to do the following...
            mRecyclerView.setHasFixedSize(true);
        }
    }
    }
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/hourly_swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@android:id/list"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:divider="@null"
        android:dividerHeight="0dp"/>

</android.support.v4.widget.SwipeRefreshLayout>