Quantcast
Channel: Kyogs
Viewing all articles
Browse latest Browse all 18

Android List view with pull to Refresh and Swipe functionality.

$
0
0
Here, I have a list (PullToRefreshSwipeListView) that implementing both of PullToRefresh  and SwipeListView library.
List can do some basic functionality like pullUp/pullDown and swipe left/right.

If you decide to use PullToRefreshSwipeListView as a view, you can define it in your xml layout like this:

<com.handmark.pulltorefresh.library.PullToRefreshSwipeListViewxmlns:swipe="http://schemas.android.com/apk/res-auto"xmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/list"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/transparent"android:cacheColorHint="@android:color/transparent"android:divider="@drawable/line_separator_repeat"android:listSelector="#00000000"ptr:ptrMode="pullFromEnd"swipe:swipeActionLeft="reveal"swipe:swipeBackView="@+id/back" //raw back viewswipe:swipeCloseAllItemsWhenMoveList="true"swipe:swipeFrontView="@+id/front" // raw front viewswipe:swipeMode="both"/>
  • swipeFrontView - Required - front view id.
  • swipeBackView - Required - back view id.
  • swipeActionLeft - Optional - left swipe action Default: 'reveal'
  • swipeActionRight - Optional - right swipe action Default: 'reveal'
  • swipeMode - Gestures to enable or 'none'. Default: 'both'
  • swipeCloseAllItemsWhenMoveList - Close revealed items on list motion. Default: 'true'
  • swipeOpenOnLongPress - Reveal on long press Default: 'true'
  • swipeAnimationTime - item drop animation time. Default: android configuration
  • swipeOffsetLeft - left offset
  • swipeOffsetRight - right offset
In java :
private PullToRefreshSwipeListView ptrList;
private SwipeListView swipeList;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_list);
ptrList = (PullToRefreshSwipeListView)findViewById(R.id.sphr_listview);
swipeList = ptrList.getRefreshableView();      
ptrList.setOnRefreshListener(new OnRefreshListener2<SwipeListView>() {
           @Override
           public void onPullDownToRefresh(PullToRefreshBase<SwipeListView> refreshView){
               // TODO Auto-generated method stub

           }

           @Override
           public void onPullUpToRefresh(PullToRefreshBase<SwipeListView> refreshView) {
               // TODO Auto-generated method stub

           }

       });
}

set adapter in list-view as shown below.
  private void setListData() {
   adapter = new DataAdapter(this, R.layout.item_library_list, new ArrayList<PurchasedItem>(), resultListView);
    
    swipeList.setSwipeListViewListener(new BaseSwipeListViewListener() {   
     @Override
        public void onClickFrontView(final int position) {
            //do something here on Frontview click
        } 
       @Override
        public void onClickBackView(final int position) {
            //do something here on Backview click
        } 

      @Override
        public void onOpened(int position, boolean toRight) {
            // TODO Auto-generated method stub
            super.onOpened(position-1, toRight);
            lastPos = position-1;
        }

        @Override
        public void onMove(int position, float x) {
            // TODO Auto-generated method stub
            super.onMove(position-1, x);
        }

        @Override
        public int onChangeSwipeMode(int position) {
            // TODO Auto-generated method stub
                        return SwipeListView.SWIPE_MODE_DEFAULT;
        }

        @Override
        public void onStartOpen(int position, int action, boolean right) {
            // TODO Auto-generated method stub
            super.onStartOpen(position-1, action, right);

        }

    });

    ptrList.setAdapter(adapter); 
    ptrList.setLongClickable(true); 
    swipeList.setSwipeOpenOnLongPress(false);  
    }

Viewing all articles
Browse latest Browse all 18

Trending Articles