I have a list that implementing both of PullToRefresh (the old one) and SwipeListView library.
Im following this to combining those library and this to use it in the Activity
.
My list can do some basic functionalities like pullUp/pullDown and swipe left/right but i encountered some bug :
- The item position in my listview is always started from 1, i believe it should be started from 0, so i need to decrease it in my methods.
- When i swipe an item (say, the first item), the item 5th item will be swiped to. So the index+4 item will also be swiped.
The code i used to initialize the objects :
private PullToRefreshSwipeListView ptrListView;
private SwipeListView resultListView;
resultListView = ptrListView.getRefreshableView();
ptrListView.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
}
});
This is the method i used to initialize the listview :
private void setListview() {
adapter = new LibraryAdapter(this, R.layout.item_library_list, new ArrayList<PurchasedItem>(), resultListView);
adapter.setListener(new LibraryListListener() {
//set the adapter
});
resultListView.setSwipeListViewListener(new BaseSwipeListViewListener() {
//position di -1 karena sejak gabung library swipelistview + pulltorefresh, position slalu kelebihan 1 & menyebabkan OutOfBound error.
@Override
public void onClickFrontView(final int position) {
//do something here
}
@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);
}
});
resultListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapter, View arg1,
final int pos, long arg3) {
//do something here
}
});
ptrListView.setAdapter(adapter);
ptrListView.setLongClickable(true);
resultListView.setSwipeOpenOnLongPress(false);
}
And this is my xml :
<com.handmark.pulltorefresh.library.PullToRefreshSwipeListView
xmlns: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"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="@+id/front"
swipe:swipeMode="both" />
Please kindly help me, any help is appreciated. Thanks