Recently encountered a problem, when using the ListView, want to display the highlight effect after the ListView item click, but in activity write the Onitemclick event of the ListView to write the color effect, click can change color, But after the ListView slide, this effect disappears? It's a tangle, why? The reason does not understand, it seems that the slide when the adapter triggered, so that the effect disappears. Later found a solution to share the following:
Add the following method to the adapter in the ListView:
/**
* Increase user clicks, get position, and change color
* @param POS
*/
public void setselectedposition (int pos) {
Selectedpos = pos;
Inform the view of this
Notifydatasetchanged ();
}
public int getselectedposition () {
return selectedpos;
}
This method is then called at the Onitemonclick event of the ListView:
public class Measureitemlistener implements onitemclicklistener{
@Override
public void Onitemclick (adapterview<?> arg0, View arg1, int arg2,
Long Arg3) {
Measurelistadapter.setselectedposition (ARG2);
dataldialog= New Loaddialogdao (Getactivity (), "Data Loading ...");
Dataldialog.show ();
map<string,string> map = (map<string,string>) arg0.getitematposition (ARG2);
measure_id = Map.get ("Measuerid");
GetData (measure_id);
}
};
The effect is that when clicked, the part of the ListView that is clicked will show the highlight effect, or you can set the effect according to your own needs.
There is a need to download my original code from GitHub, the address is: Https://github.com/maliankun/listview/archive/master.zip
This article from "Mo Panic, raise straight forward" blog, please be sure to keep this source http://kunyali.blog.51cto.com/4890065/1554850
Android ListView Item Click to display the Click Effect