android - RecyclerView items: how to save properties of Views in every row? -


my problem understand how recyclerview works.. have recyclerview little bit complicated item in every row, main thing item has child imageview , linearlayout. want press imageview , set visibility of linearlayout gone or visible , rotate imageview. tried in onbindviewholder:

        holder.mivexpandbtn.setonclicklistener(new onclicklistener() {         boolean isopen = false;         @override         public void onclick(view v) {              if (isopen) {                 counterlistadapter.this.notifyitemchanged(position);                 holder.mlldetails.setvisibility(gone);                 holder.mdivider.setvisibility(visible);                 holder.setarrowup(false);                 isopen = false;                 counteritem.setdetailsopened(false);             } else {                 holder.mlldetails.setvisibility(visible);                 holder.mdivider.setvisibility(gone);                 holder.setarrowup(true);                 isopen = true;                 counteritem.setdetailsopened(true);             }         }     }); 

and have problems here.

  • i have boolean variable inside onclicklistener, know wrong, changes 1 time when expand linearlayout. if make boolean global variable, if expand 1 row of recyclerview isopen = true other item , doesn't expand when click on imageview.. should place boolean?
  • and second question - how can save state of recyclerview rows on screen rotation? example expanded 1 of rows, linearlayout.setvisibility(visible), change screen orientation , closed.

for first problem, should put boolean variable define views, i.e., inside viewholder, ir order onclick call boolean way

if(holder.isopen) 

in way keep reference of each boolean each row.

for second problem, solution pretty simple. in manifest, in activity have recyclerview, define following:

android:configchanges="keyboardhidden|orientation|screensize" 

this prevents activity being recreated on configuration change in case rotate screen, activity keep it's state , recyclerview therefor not recreated along adapter.

notice means that, if activity not recreated, onpause, onstop, etc, not run. screen rotation, activity still run method onconfigurationchanged() should define changes need in case screen rotates.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -