Dr.KeyOk
Dr.KeyOk

Reputation: 768

How to change position of Adapter in Android

In my application I want change set new value to position of recyclerview adapter.
With java language I can it with below code:

@Override
public void onBindViewHolder(MonthFragmentAdapter.ViewHolder holder, int position) {
    position += 6 - (position % 7) * 2;
}

But in kotlin I can't use below code and show me val error for position.

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    position += 6 - position % 7 * 2
}

Show me Val cannot be reassigned! I know I can't set new value for val, but how can I change my code for fix it?

Upvotes: 0

Views: 94

Answers (2)

GHH
GHH

Reputation: 2019

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    var newPosition = position
    newPosition += 6 - newPosition % 7 * 2
}

Use a new variable to change the value.

It is Kotlin feature, you can't change the function parameter.

Upvotes: 1

Hassan Zulfiqar
Hassan Zulfiqar

Reputation: 1

chainging adapter position is not possible, but you can do it with taht way if (position == yourposition){//do that}

Upvotes: 0

Related Questions