This article describes the method of Android programming to implement the click expansion and hidden of Listview. Share it for your reference, as follows:
There are many codes, so I find key points and post them. I believe that you will easily understand after reading them.
In listview activity
List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>() myAdapter = new MyAdapter(getApplicationContext(), listItems); (myAdapter); (new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { //Set the selected number when clicking, and set the property selectItem in the custom adapter (arg2); //Refresh listView (); } });
In the custom myAdapter getView, what I need to hide and display is that the TableLayout is hidden by default, and the default values of the int-type selectItem and sign are both -1.
TableLayout info = (TableLayout)(.tableLayout1); if(position == selectItem){//The selected element if(sign == selectItem){// When selected again, it will be hidden and the mark position will be initialized (); //The transparent color is not selected (("#00000000")); sign = -1; }else{//It will be displayed when selected and marked with this position (); //Selected to set background color (("#B0E2FF")); sign = selectItem; } }else {//Unselected elements (); (("#00000000")); }
You can click to display, click to hide again, click to display only one element will be displayed.
I hope this article will be helpful to everyone's Android programming design.