How to get children of a layout manager that are not yet visible in recyclerview adapter?

MHSFisher

I am connecting two recyclerView as you seen in the picture.

the image

one of them is sectioned recyclerView with header. (the bottom one)

another one is a recyclerView that shows the headers of bottom one as tab. (the top one)

I dynamically get the dataset for them with Retrofit and setting them separately

I want to highlight the top one items by scrolling the bottom one. Scrolling is successfully done and when bottom recyclerView scrolled and get to its header position, top recyclerView goes to that specific position. Now as I scrolled to that position, also I want to highlight that.

I use an xml file for change the color of item when selected :

<selector xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:drawable="@color/chooseCAndZ" android:state_selected="true"/>
   <item android:drawable="@color/colorAccent" android:state_focused="true"/>

</selector>

and do the below job for change the color of top recyclerView when clicked and it works great :

@Override
public void onBindViewHolder(final FoodTopMenuAdapter.ViewHolder holder, int position) {

    holder.mView.setSelected(selectedPos == holder.getAdapterPosition());

    holder.mView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Integer index = inList.get(holder.getAdapterPosition());
            linearLayoutManager.scrollToPosition(index);

            if (holder.getAdapterPosition() == RecyclerView.NO_POSITION) return;

            notifyItemChanged(selectedPos );
            selectedPos  = holder.getAdapterPosition();
            notifyItemChanged(selectedPos );

        }
    });
}

also do this job for scrolling to the specific position in bottom recyclerView onBindViewHolder:

index = inList.get(vheader.getHeaderCategory());
foodRVLayoutManager.scrollToPosition(index);

now the idea is to get the specific view from foodRVLayoutManager.getChildAt(i).setSelected(true); to change the view color as selected.

but the main problems are these :

** the foodRVLayoutManager just can get children that are visible! it means that changing the color is works for visible children.

** the onClick and scrollToPosition interference each other.

MHSFisher

finally I solved the problem just by changing foodRVLayoutManager.scrollToPosition(index); to foodRVLayoutManager.scrollToPositionWithOffset(index, 3);

by setting offset, invisible items become visible before highlight.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Get visible items in RecyclerView

From Java

recyclerview No adapter attached; skipping layout

From Dev

How to get item from RecyclerView adapter in Android

From Dev

How to get View in RecyclerView.Adapter for Snackbar?

From Dev

Android: RecyclerView: No adapter attached; skipping layout

From Dev

How to get Layout width modified in RecyclerView

From Dev

RecyclerView Adapter Layout not showing icon

From Dev

How to get runtime permissions in adapter of a RecyclerView? Please see details

From Dev

Percentage of a layout inside RecyclerView visible on Screen

From Dev

How to get clicks on RecyclerView (NOT the children)

From Dev

How to access LayoutManager from RecyclerView.Adapter to get scrollToPosition?

From Dev

Android studio retrieve data from Fiewbase and get error E/RecyclerView: No adapter attached; skipping layout

From Dev

How to get arraylist from recyclerview adapter in android kotlin

From Dev

how to get the update manager window visible?

From Dev

How to get the position of the last visible item inside an Adapter in Android

From Dev

How to get layout children - getChildAt() returning null

From Dev

how to visible layout in android

From Dev

Recycleview RecyclerView: No adapter attached; skipping layout

From Dev

E/RecyclerView: No adapter attached; skipping layout

From Dev

use same recyclerview adapter with different layout

From Dev

How to make a RecyclerView adapter to get 3 items of an arraylist in every row

From Dev

How to use multiple layout using one RecyclerView Adapter?

From Dev

Using RecyclerView Adapter - Error E/RecyclerView: No adapter attached; skipping layout

From Dev

How to get the visible list items count in a Xamarin android Array adapter

From Dev

RecyclerView Layout Manager Manipulation

From Dev

How to make recyclerview layout manager like stack view?

From Dev

How to get the actual size of the children during layout computation in JavaFX?

From Dev

E/RecyclerView: No adapter attached; skipping layout (Android)

From Dev

How to update text from recyclerview adapter to other layout xml

Related Related

  1. 1

    Get visible items in RecyclerView

  2. 2

    recyclerview No adapter attached; skipping layout

  3. 3

    How to get item from RecyclerView adapter in Android

  4. 4

    How to get View in RecyclerView.Adapter for Snackbar?

  5. 5

    Android: RecyclerView: No adapter attached; skipping layout

  6. 6

    How to get Layout width modified in RecyclerView

  7. 7

    RecyclerView Adapter Layout not showing icon

  8. 8

    How to get runtime permissions in adapter of a RecyclerView? Please see details

  9. 9

    Percentage of a layout inside RecyclerView visible on Screen

  10. 10

    How to get clicks on RecyclerView (NOT the children)

  11. 11

    How to access LayoutManager from RecyclerView.Adapter to get scrollToPosition?

  12. 12

    Android studio retrieve data from Fiewbase and get error E/RecyclerView: No adapter attached; skipping layout

  13. 13

    How to get arraylist from recyclerview adapter in android kotlin

  14. 14

    how to get the update manager window visible?

  15. 15

    How to get the position of the last visible item inside an Adapter in Android

  16. 16

    How to get layout children - getChildAt() returning null

  17. 17

    how to visible layout in android

  18. 18

    Recycleview RecyclerView: No adapter attached; skipping layout

  19. 19

    E/RecyclerView: No adapter attached; skipping layout

  20. 20

    use same recyclerview adapter with different layout

  21. 21

    How to make a RecyclerView adapter to get 3 items of an arraylist in every row

  22. 22

    How to use multiple layout using one RecyclerView Adapter?

  23. 23

    Using RecyclerView Adapter - Error E/RecyclerView: No adapter attached; skipping layout

  24. 24

    How to get the visible list items count in a Xamarin android Array adapter

  25. 25

    RecyclerView Layout Manager Manipulation

  26. 26

    How to make recyclerview layout manager like stack view?

  27. 27

    How to get the actual size of the children during layout computation in JavaFX?

  28. 28

    E/RecyclerView: No adapter attached; skipping layout (Android)

  29. 29

    How to update text from recyclerview adapter to other layout xml

HotTag

Archive