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