Recording the status of the row marked by listview in Android

Source: Internet
Author: User

There is nothing special about the small demo. The most special thing is to use notifydatasetchanged as little as possible, which is too costly. Of course, it will save a lot of work, but sometimes it will still encounter other problems, project experience indicates that this is possible. If you have little nonsense, you can directly use the key code.

@ Override public void onitemclick (adapterview <?> Adapterview, view, int POs, long arg3) {/*** in listview, the value of getchildat (INDEX) can only be the current visible area (the list can be rolled) subitem! 1. If you want to obtain the front part, the null value will be returned; 2. the getchildcount and getcount values will be different (a large number ); 3. If getchildat (INDEX) is used ). findviewbyid (...) if the value is set, the value of the scrolling list changes. Use getfirstvisibleposition () to obtain the first visible position. Use the current position-getfirstvisibleposition () and then use getchildat! **/INT now_pos = pos-adapterview. getfirstvisibleposition (); view v = adapterview. getchildat (now_pos); imageview = (imageview) v. findviewbyid (R. id. image); If (imageview. getvisibility () = view. visible) {imageview. setvisibility (view. gone); adapter. setstate (Pos, nonbiaozhi);} else {imageview. setvisibility (view. visible); adapter. setstate (Pos, biaozhi); // used for getview callback, but not very expensive. // adapter. notifydatasetchanged (); // If policydatasetchanged is not used, getview will not be refreshed to improve the efficiency of refreshlistview (Pos, imageview );}}

 

public void refreshListView(int pos, ImageView imageView) {        if(pre != pos && !hasmap.isEmpty()){            ImageView image = (ImageView) hasmap.get(pre);            image.setVisibility(View.GONE);            hasmap.remove(pre);        }        pre = pos;        hasmap.put(pre, imageView);    }

The above is the method fragment in the activity, and the following is the baseadapter method fragment:

// Set the public void setstate (INT POs, int state) {If (State = mainactivity. biaozhi) {// The list is cleared at each vertex to maintain a unique selection map. clear (); map. put (Pos, 1);} else {map. remove (POS) ;}/// register the public Boolean getstate (INT p) {If (! Map. isempty () & map. containskey (p) {return true;} else return false ;} ============================== getview code: // fixed display of the marked row if (getstate (position) {holder. imageview. setvisibility (view. visible);} else holder. imageview. setvisibility (view. gone );

Download the project and run it on your own to get the title effect. Listviewclicktest.zip

Related Article

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.