Android:recyclerview Partial refresh that something ~

Source: Internet
Author: User

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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.