Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll TableView programmatically by the desired column position #21

Closed
evrencoskun opened this issue Jan 13, 2018 · 5 comments
Closed
Assignees
Labels

Comments

@evrencoskun
Copy link
Owner

evrencoskun commented Jan 13, 2018

one question: for your TableView library, how do you scroll to a column say column 20?

Hi @sidharthshah,

It is actually pretty simple. If you checked the source code, you can see TableView occurs from 3 Skilled RecyclerViews.

If you want to scroll horizontally, you can use scrollToPosition method of LayoutManager.

For example:

        int position = 10;

        scrollCell(position);
        scrollColumnHeader(position);

Below helper methods will be on the new version too. For now, you can insert them on your project.

private void scrollCell(int columnPosition) {
        CellLayoutManager cellLayoutManager = tableView.getCellLayoutManager();

        for (int i = cellLayoutManager.findFirstVisibleItemPosition(); i < cellLayoutManager
                .findLastVisibleItemPosition() + 1; i++) {

            ColumnLayoutManager columnLayoutManager = (ColumnLayoutManager) ((RecyclerView)
                    cellLayoutManager.findViewByPosition(i)).getLayoutManager();

            columnLayoutManager.scrollToPosition(columnPosition);
        }
    }

    private void scrollColumnHeader(int columnPosition) {
        tableView.getColumnHeaderLayoutManager().scrollToPosition(columnPosition);
    }
@gmcodebuster
Copy link

I have added above 2 methods in AbstractTableAdapter class of library and calling both method in Fragment onCreateView() after setting Adapter. In my case scrollColumnHeader(position) scrolls header to specific position, but scrollCell(position) does not scroll cell columns to specific position.

Can you tell me what I am doing wrong?

@evrencoskun
Copy link
Owner Author

evrencoskun commented Jan 13, 2018

Hi @gmcodebuster,

The reason is TableView stores scroll position for Cell columns.

In CellRecyclerViewAdapter, TableView sets each cell column scroll position when before each cell row is getting visible. See below code

@Override
    public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
        super.onViewAttachedToWindow(holder);

        // The below code helps to display a new attached recyclerView on exact scrolled position.
        CellRowViewHolder viewHolder = (CellRowViewHolder) holder;
        ((ColumnLayoutManager) viewHolder.m_jRecyclerView.getLayoutManager())
                .scrollToPositionWithOffset(m_iHorizontalListener.getScrollPosition(),
                        m_iHorizontalListener.getScrollPositionOffset());

So, below functions don't work before TableView cell is not visible on screen.

        scrollCell(position);
        scrollColumnHeader(position);

You can say "What is the solution on my case ?"

You need to find a way to call above codes after when all cell is visible. or You need to hack TableView source to change default values of HorizontalRecyclerViewListener class.

or wait the newest version!

See you

@evrencoskun evrencoskun self-assigned this Jan 13, 2018
@evrencoskun
Copy link
Owner Author

evrencoskun commented Jan 21, 2018

Hi @gmcodebuster @sidharthshah,

0.8.5.4 version has been just released. With this version there are 2 helper method in TableView.

These are ;

tableView.scrollToColumnPosition(int column)
tableView.scrollToRowPosition(int row)

These methods will help your request.

Please test your issue with the newest version and let me know the result.

@gmcodebuster
Copy link

@evrencoskun ,

Thanks for adding scroll to position in recent release. I will integrate it in code and inform you about result.

@gmcodebuster
Copy link

@evrencoskun,
Scroll to position works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants