For the tag in the ListView, click the item background toggle. Letting go won't change.

Source: Internet
Author: User

Tag can be used to keep a view that is currently clicked. The next time you click, you can clear the background of the reserved view.

Menulist.setonitemclicklistener (New Adapterview.onitemclicklistener () {
@Override
public void Onitemclick (adapterview<?> parent, view view, int position, long ID) {
View tag= (view) Parent.gettag ();
if (tag! = null)
{
if (Tag.getid () ==id) return;
Tag.setbackgroundresource (r.drawable.disselected);
}
View.setbackgroundresource (r.drawable.selected);
Parent.settag (view);
}
});

The adapter above uses the background color option of the initialization list view that you wrote.

Import java.util.List;
Import Java.util.Map;

Import Android.content.Context;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.SimpleAdapter;



public class Changebgadapter extends Simpleadapter {
@Override
Public View GetView (int position, View Convertview, ViewGroup parent) {
TODO auto-generated Method Stub
View v = super.getview (position, convertview, parent);
V.setbackgroundresource (r.drawable.disselected);

return v;
}

Public Changebgadapter (context context, list<?. extends Map<string,?>> data, int resource, string[] from, int[ ] to) {
Super (context, data, resource, from, to);
}
}

For the tag in the ListView, click the item background toggle. Letting go won't change.

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.