Advanced_Android_Development icon indicating copy to clipboard operation
Advanced_Android_Development copied to clipboard

Auto jump to DetailFragment in branch bonus_recyclerview_code

Open luciferldy opened this issue 8 years ago • 0 comments

in your code, autoSelectView=true in the method onLoadFinish() in Class ForecastFragment

updateEmptyView();
        if ( data.getCount() > 0 ) {
            mRecyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                    // Since we know we're going to get items, we keep the listener around until
                    // we see Children.
                    if (mRecyclerView.getChildCount() > 0) {
                        mRecyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
                        int itemPosition = mForecastAdapter.getSelectedItemPosition();
                        if ( RecyclerView.NO_POSITION == itemPosition ) itemPosition = 0;
                        RecyclerView.ViewHolder vh = mRecyclerView.findViewHolderForAdapterPosition(itemPosition);
                        if ( null != vh && mAutoSelectView ) {
                            mForecastAdapter.selectView( vh );
                        }
                        return true;
                    }
                    return false;
                }
            });
        }

app will invoke onClick() method and jump to DetailActivity, is that right in logic?

luciferldy avatar Oct 05 '16 13:10 luciferldy