TableView
TableView copied to clipboard
Can't scrolling up when inside SwipeRefreshLayout
It's doing refresh instead of scrolling up
If TableView
inside of SwipeRefreshLayout
in the xml, it's work fine if i'm scrolling down, but when i'm trying to scroll up the table, it's doing refresh
instead of scrolling up, can you fix that?
My current .xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.evrencoskun.tableview.TableView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/test" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Can you fix this? Or it's just my fault?
Hi @ioterateam, you need to disable swipeRefreshLayout until 1first row is fully visible (so SwipeLayout do not get the events).
- Extend TableView (MyTableView)
- add a TouchHandler in MyTableView
TouchHandler mTouchHandler;
+ add setter - Override
dispatchTouchEvent(MotionEvent ev)
- call
mTouchHandler.onTouchEvent(ev)
- in your fragment/activity set your TouchHandler on MyTableView:
setTouchHandler(this);
- implement the touch handler:
onTouchEvent(MotionEvent ev) { mSwipeRefreshLayout.setEnabled(getRowHeaderLayoutManager().findFirstCompletelyVisibleItemPosition() == 0) }
you might want to check if the event is DOWN or MOVE, depending what you achieve.
I tried to use the @sonique6784 answer. It doesn't work that well. It's always stuck at the first touch -> the row move from 4,5 to 0. and next touch the swipe refreshlayout is enable (need at least 2 touches)
So please @evrencoskun add the pull to refresh layout feature for the table
you can try this
//解决滑动冲突 tableView.getCellRecyclerView().addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); refreshLayout.setEnabled(tableView.getCellLayoutManager().findFirstVisibleItemPosition() == 0); } });
@83849 's answer is genius, completely works for me. A better way is to change findFirstVisibleItemPosition() to findFirstCompletelyVisibleItemPosition() to make sure the first item is completely visible, then you set the swipe refresh layout to be enabled.