2

I have a Custom gridView and a Button in Frame Layout. Code is following

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
     <GridView
        android:id="@+id/gridview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/Rel_Spinner"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth" >
    </GridView>


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >


        <Button
            android:id="@+id/btnLoadMore"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Load More" />

    </FrameLayout>

</RelativeLayout>

It loads images and Text from adapter. as shown in figure

enter image description here

Now I want is that the Button should appear when the final position of the GridView Scroll is reached other wise it should again disappear. as shown in figure.

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124

1 Answers1

0

you can do this by using setOnScrollListener for GridView as:

gridview.setOnScrollListener(new OnScrollListener() {

   @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
              int visibleItemCount, int totalItemCount) {

      }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub
      switch(scrollState) {
        case 2: // SCROLL_STATE_FLING 
        //hide button here
        break;

        case 1: // SCROLL_STATE_TOUCH_SCROLL 
        //hide button here
        break;

        case 0: // SCROLL_STATE_IDLE 
        //show button here
        break;

            default:
             //show button here
        break;
           }
        }
     });
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • Thanks for the Answer. its Working as i Needed. But the strategy changed here. boss said me that you should load more images in the gridView on the scroll listner only not by using a Extra Button (Load More). Initially my gridView is filled with 12 images and 12 textViews. So How can i load more 12 images and text when i reached at the last Item of the GridView i.e the 12th item. Please Help in this regard. – Qadir Hussain Dec 20 '12 at 06:15
  • @QadirHussain : see [this](http://stackoverflow.com/questions/12170466/android-using-gridview-with-onscrolllistener) maybe helpful in solving current issue – ρяσѕρєя K Dec 20 '12 at 06:18