Android Programming Implementation ListView Click to expand and hide the method _android

Source: Internet
Author: User
Tags transparent color

This article describes the Android programming implementation ListView Click to expand and hide the method. Share to everyone for your reference, specific as follows:

Code more, so find the key point everyone posted out, I believe that we read it very easy to understand,

In the activity of ListView

list<map<string, object>> ListItems = new arraylist<map<string, object>> ()
myAdapter = new Myadapter (Getapplicationcontext (), listitems);
Listview.setadapter (myadapter);
Listview.setonitemclicklistener (New Onitemclicklistener () {
 @Override public
 void Onitemclick (Adapterview <?> arg0, View arg1, int arg2,
   long arg3) {
   //Click to set selected number, set properties
   in custom adapter SelectItem Myadapter.setselectitem (arg2);
   Refresh ListView
   myadapter.notifydatasetinvalidated ();
 }
});

In the custom Myadapter GetView, what I need to hide and display is a tablelayout default is hidden, the definition attributes int SelectItem and the sign default values are-1,

Tablelayout info = (tablelayout) Convertview.findviewbyid (R.ID.TABLELAYOUT1);
if (position = = SelectItem) {//Selected element
  if (sign = = SelectItem) {//Once again selected will be hidden and the mark position
     info.setvisibility ( View.gone);
     Set Transparent Color
   convertview.setbackgroundcolor (Color.parsecolor ("#00000000") without being selected;
   sign =-1;
  } The else{//is displayed when selected and marked with
     info.setvisibility (view.visible);
     is selected to set the background color
   convertview.setbackgroundcolor (Color.parsecolor ("#B0E2FF"));
   sign = SelectItem;
 }
else {//unselected element
  info.setvisibility (view.gone);
  Convertview.setbackgroundcolor (Color.parsecolor ("#00000000"));
}

Can be achieved by clicking on the show, click Hide again, click on the show will only have an element to show

I hope this article will help you with the Android program.

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.