// method to collapse all groups private void collapseAll(int skip) { int count = listAdapter.getGroupCount(); for (int i = 0; i < count; i++) { if (i != skip) myList.collapseGroup(i); } }
private void expandAll() { int count = listAdapter.getGroupCount(); for (int i = 0; i < count; i++) { myList.expandGroup(i); } }
public void afterTextChanged(Editable s) { String inputTxt = txt.getText().toString().toLowerCase(); String brightString = inputTxt; String colorString = ""; int groupPosition; int count = 0; int countB = 0; expandAll(); // fel, kolla en bool typ, om checkText = true; System.out.println("click: " + click); if (click == true) { click = false; return; } // check if the text contains a / if (inputTxt.contains("/") && inputTxt.length() > 1) { String[] separated = inputTxt.split("/"); if (inputTxt.startsWith("/")) { brightString = separated[1]; colorString = ""; if (separated.length > 2) { brightString = separated[1]; colorString = separated[2]; } } else { if (separated.length > 1) { brightString = separated[0]; colorString = separated[1]; } else { brightString = separated[0]; colorString = ""; } } } // System.out.println("brString: " + brightString); // System.out.println("colString: " + colorString); // check the header for (int i = 0; i < listAdapter.getGroupCount(); i++) { // get the group header Brightness headerInfo = brightList.get(i); if (headerInfo.getName().startsWith(brightString)) { groupPosition = brightList.indexOf(headerInfo); txt.setBackgroundColor(android.graphics.Color.WHITE); countB = 1; // loop through the children for (int j = 0; j < headerInfo.getColorList().size(); j++) { // get the child info Color childInfo = headerInfo.getColorList().get(j); if (childInfo.getName().startsWith(colorString) && colorString.length() > 0) { // expand other groups collapseAll(groupPosition); count = 1; // check if the whole word is typed if (colorString.contains(childInfo.getName())) { index = myList.getFlatListPosition( ExpandableListView.getPackedPositionForChild(i, j)); myList.setItemChecked(index, true); } } } if (count == 0 && colorString.length() > 0) { txt.setBackgroundColor(android.graphics.Color.RED); myList.setItemChecked(index, false); return; } } if (countB == 0 && brightString.length() > 0) { if (brightString.startsWith("/")) txt.setBackgroundColor(android.graphics.Color.WHITE); else txt.setBackgroundColor(android.graphics.Color.RED); } } }