1

I have a recyclerview displaying list of items in horizontal. I am displaying a list of articles with title and description:

    mRecyclerView = findViewById(R.id.rvmain);
    mRecyclerView.setOnFlingListener(null);
    SnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(mRecyclerView);
    mLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new MainActivityRVAdapter(postsModels,MainActivity.this);
    mRecyclerView.setAdapter(mAdapter);

In my menu I have two items onclicking clicking which i want to change the font size of that particular recyclerview which is shown

<item
    android:id="@+id/fontincrease"
    android:title="@string/fontincrease"
    app:showAsAction="always"
    />
<item
    android:id="@+id/fontdecrease"
    android:title="@string/fontdecrease"
    app:showAsAction="always"
    />

Now how to process from here i am not able to understand

I know the code to increase font size:

float size = mViewShabad.getTextSize()*1.1f;
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);

I have to get the viewholder and increase the font of the description.

I googled and got the below line to be used to access the elements in the viewholder.

int position = ((LinearLayoutManager)mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
(TextView) mRecyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.title)

I am able to change the font size, but i want to reset it when i scroll

I am trying:

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() 
{
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
        // what to do here so that everything is shown the default way
    }
});
Santhosh
  • 9,965
  • 20
  • 103
  • 243
  • without `position` how can one identify which item to change? i couldn't get you. – Sivakumar S Mar 06 '18 at 13:56
  • I am trying to get the position: by `int position = mLayoutManager.findFirstVisibleItemPosition();` but it says cannot resolve method findFirstVisibleItemPosition() – Santhosh Mar 06 '18 at 13:58
  • 1
    https://stackoverflow.com/questions/29463560/findfirstvisibleitempositions-doesnt-work-for-recycleview-android to find positon, can u try – Sivakumar S Mar 06 '18 at 13:59
  • https://stackoverflow.com/questions/29327013/android-cannot-resolve-method-findfirstvisibleitemposition – Rajen Raiyarela Mar 06 '18 at 14:04

1 Answers1

0

let after changing the font size position of visible view holder (Containing textview) is 2
than globally take a current position holder as

int currentPos = -1;

Note: default value of currentPos is -1. Set currentPos = 2 after updating font
Now on scroll

@Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
        if(currentPos != -1){
           // change the font of view holder at current pos (which is 2)
           currentPos = -1;
         }

    }
Sanjay Kumar
  • 1,135
  • 14
  • 27