Android ListView Item Click to show click Effect

Source: Internet
Author: User

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

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.