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.