1. Introduction of local refreshes
Referring to Recyclerview, the first thing we think of is the ListView, for a local refresh of the ListView, we have previously had a solution, [Android:listview's partial refresh] The solution was: record the clicked item's position And then during the update process, constantly judging whether the position is somewhere between the visible item and if it is, then update, no, not update.
Partial update of 2.RecyclerView
In line with the previous idea, the first thing to look for is the location range of the item visible in Recyclerview, which is not in Recyclerview, but in Linearlayoutmanager, such as:
int Fristpos = Layoutmanager.findfirstvisibleitemposiint Lastpos = layoutmanager.findlastvisibleitemposition (); if ( Position >= fristpos && position <= lastpos) { View view = Recyclerview.getchildat (position); ...}
Then find the corresponding view, update it (recursive lookup)
/** * Search by ID in ViewGroup * @param VG * @param ID such as: R.id.tv_name * @return */private View Findviewinviewgroupbyid (Viewgrou P VG, int id) {for (int i = 0; i < Vg.getchildcount (); i++) {View v = vg.getchildat (i); if (v.getid () = = ID) {return v;} else {if (v instanceof viewgroup) {return Findviewinviewgroupbyid ((ViewGroup) v, id);}}} return null;}
3. New ideas: notifyitemchanged
Recyclerview Unlike the ListView, with only one update notifydatasetchanged, it not only retains the features of the ListView update, but also specifically updates for the "Add, remove, update" action, which can only update one item, You can also update part of the item, so it's more efficient to use. Therefore, the local refresh of Recyclerview can be done by modifying the data source by calling notifyitemchanged (position).
4. Optimization
Although only a single item is updated, it does not cause flicker, but if a single item is complex, for example, the item needs to load pictures from the network, and so on. To avoid flashing as many times as possible, we can set a tag for ImageView at the time of loading, such as Imageview.settag (Image_url), and before the next reload, get the tag first, such as ImageUrl = Imageview.gettag (), if the address at this time is the same as the previous address, we do not need to load, if not the same, and then load.
-------------------------------------------------------------------
more communication, Android Development Alliance QQ Group: 272209595
Android:recyclerview Partial refresh that something ~