0

Pull to refresh list view(pull) not working inside scroll view .. it is not scrolling ..

Here is my xml file.

 <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:padding="10dp" 
            android:background="#fff">

            <ImageView
                android:id="@+id/profile_image"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:scaleType="fitXY"
                android:src="@drawable/loading_image" />

            <TextView
                android:id="@+id/user_name"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:paddingLeft="10dp"
                android:text="testcase1" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:src="@drawable/clock_icon" />

            <TextView
                android:id="@+id/time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1 day(s)ago"
                android:textColor="@color/Gray" />
        </LinearLayout>

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:src="@drawable/loading_image_large"
            android:scaleType="fitXY"/>

        <TextView
            android:id="@+id/likes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/clap"
            android:drawablePadding="10dp"
            android:padding="10dp"
            android:text="1 like(s)"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="view all comments"
            android:textColor="@color/Gray" />




      <com.handmark.pulltorefresh.library.PullToRefreshListView
            android:id="@+id/comments_listview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp" />
        <EditText
            android:id="@+id/comment_editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_marginRight="5dp"
            android:background="@drawable/gray_stroke_sec"
            android:hint="New Comment"
            android:inputType="textCapSentences|textMultiLine"
            android:maxLines="3"
            android:minHeight="40dp"
            android:padding="10dp"
            android:scrollHorizontally="true"
            android:textSize="@dimen/text_size_14" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp" >

            <ImageView
                android:id="@+id/like_image"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/like" />

            <ImageView
                android:id="@+id/repost"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/repost" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="4"
                android:gravity="right|center_vertical" >

                <TextView
                    android:id="@+id/comment"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/comment_bg"
                    android:gravity="center"
                    android:padding="10dp"
                    android:text="Comment"
                    android:textColor="#fff"
                    android:textSize="16sp"
                    android:clickable="true"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</ScrollView>
Gagan
  • 745
  • 10
  • 31

2 Answers2

0

Well obviously it should not be done what you are willing to do.Ite not recommended But still you can put your PullToRefreshView in linearLayout if you want it to work

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:orientation="vertical">

   <com.handmark.pulltorefresh.library.PullToRefreshListView
        android:id="@+id/comments_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

 </LinearLayout>

Still wanna let you know,this is not Recommended.

Neal Ahluvalia
  • 1,538
  • 1
  • 10
  • 20
0

This is using the Android Support SwipeRefreshLayout instead.

From http://nlopez.io/swiperefreshlayout-with-listview-done-right/

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

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/guides_no_results"
            android:id="@+id/empty_view"
            android:gravity="center"
            android:padding="16dp"
            android:fontFamily="sans-serif-light"
            android:textSize="20sp"
            android:visibility="gone"/>


        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:drawSelectorOnTop="true"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:id="@+id/guides_list" />

    </LinearLayout>

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

and then in code:

guidesList.setOnScrollListener(new AbsListView.OnScrollListener() {  
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {

    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        int topRowVerticalPosition =
            (guidesList == null || guidesList.getChildCount() == 0) ? 0 : guidesList.getChildAt(0).getTop();
        swipeContainer.setEnabled(firstVisibleItem == 0 && topRowVerticalPosition >= 0);
    }
});
patrick.elmquist
  • 2,113
  • 2
  • 21
  • 35