2

I'm using HorizontalGridView in android.support.v17.leanback.widget package. The problem is that OnChildViewHolderSelectedListener is called too early.

    horizontalGrid.setSelectedPosition(position);
    horizontalGrid.setOnChildViewHolderSelectedListener(new OnChildViewHolderSelectedListener() {
        @Override
        public void onChildViewHolderSelected(RecyclerView parent, RecyclerView.ViewHolder child, int position, int subposition) {
            super.onChildViewHolderSelected(parent, child, position, subposition);
            //the animation isn't complete
            //horizontalGrid.getLayoutManager().isSmoothScrolling() is true;
        }
    });

The only choices that I'm aware of is to use a TimerTask with Timer and check if horizontalGrid.getLayoutManager().isSmoothScrolling() is false. Another less reliable solution is to use a Handler with postDelayed method. Both ways are ugly in my case. I haven't found any built-in methods. Am I missing something? Is there something more elegant?

serg66
  • 1,148
  • 1
  • 17
  • 31
  • I have the same problem. I'm trying to find the X coordinate of the selected child, but the value is wrong because this callback comes before the animation changes the view's position. I tried with `onChildViewHolderSelectedAndPositioned`, but it didn't help - it is not called all the time and the X coordinate is still wrong anyway. – Edward Jun 06 '19 at 14:45

0 Answers0