滑动以刷新不使用列表视图

时间:2016-10-11 09:14:14

标签: android listview swiperefreshlayout

我现在已经坚持这个问题两天了。如果有人能够找到答案,将非常感谢你的帮助。

基本上,我正在尝试为我的CardFragment实现Swipe To Refresh,它将同时包含listview和gridview。添加Swipe To Refresh标记后,根本不会触发setOnRefreshListener,除非我使用鼠标滚动条滚动,否则listview无法滚动。

下面是我的fragment_main.xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:clickable="true"
    android:weightSum="11">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:id="@+id/linearButtons">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/singapore"
            android:id="@+id/leftButton"
            android:layout_weight="0.5"
            android:textStyle="bold"
            android:background="@drawable/default_button"
            android:layout_margin="5dp" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/world"
            android:id="@+id/rightButton"
            android:textStyle="bold"
            android:background="@drawable/default_button"
            android:layout_weight="0.5"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#d6d6d6"
        android:id="@+id/linearInspection">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Inspection Checklist"
            android:id="@+id/txtChecklist"
            android:textStyle="bold"
            android:textSize="15sp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true">

        <android.support.v4.widget.SwipeRefreshLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true"
            android:id="@+id/main_swipe">

            <ListView
                android:id="@+id/lvNews"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbarSize="3dp"
                android:scrollbarStyle="outsideOverlay"
                android:scrollbars="vertical"
                android:scrollingCache="true"
                android:smoothScrollbar="true"
                android:clickable="true"
                android:longClickable="true" />

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

            <GridView
                android:id="@+id/gridview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:verticalSpacing="10dp"
                android:horizontalSpacing="10dp"
                android:gravity="center"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginBottom="10dp"
                android:scrollbarSize="3dp"
                android:scrollbarStyle="outsideOverlay"
                android:scrollbars="vertical"
                android:scrollingCache="true"
                android:smoothScrollbar="true"
                android:longClickable="true"/>


    </LinearLayout>
</LinearLayout>

CardFragment.java:

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_main, container, false);

        mSwipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.main_swipe);
        mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                // Do work to refresh the list here.
                mSwipeRefresh.setRefreshing(true);
                Log.d("REFRESH", "REFRESH");
                new Task().execute();
            }
        });
}

实际上,我编写fragment_main.xml的方式有什么问题吗?

0 个答案:

没有答案