androidandroid-recyclerviewexpandablelistviewexpandablerecyclerview

Expandable recylerview with first item of the list open on start of the activity?


I am working on Xamarin Android.I have implemented an expandable recycler view whichs open on click of the view(here linearLayoutRatingCard). The card is the view which opens on click of the linearLayoutRatingCard. But I want the first item of the recycler view to be open at the start of the activity. I have tried it by taking the position of the recycler adapter but it is not working as intented. Here is the code of my OnBindViewHolder.

int mExpandedPosition = -1;
ViewGroup root;

public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
        MyRatingViewHolder myholder = (MyRatingViewHolder)holder;
        Rating = RatingList[position];
        pos = position;
        myholder.textViewRatingTitle.Text = Rating.RatingTitle;

        bool isExpanded = position == mExpandedPosition;
        myholder.card.Visibility = isExpanded ? ViewStates.Visible : ViewStates.Gone;
        myholder.linearLayoutRatingCard.Activated = isExpanded;
        //if (position == 0)
        //{
            //myholder.card.Visibility = ViewStates.Visible;
            //myholder.linearLayoutRatingCard.Activated = true;
            //mExpandedPosition = 0;
            //TransitionManager.BeginDelayedTransition(root);
       // }

        myholder.linearLayoutRatingCard.Click += (sender, e) =>
            {
                mExpandedPosition = isExpanded ? -1 : position;
                TransitionManager.BeginDelayedTransition(root);
                NotifyDataSetChanged();
            };

        myholder.card.Click += (sender, e) =>
        {
            myholder.card.Visibility = ViewStates.Gone;
        };
}

Solution

  • Try with int mExpandedPosition =0

    This way the start position in the check will be 0.