When adding an ExpandedListView type list to the fragment, the text color of the elements of this list is set to white and, of course, on a white background, the list is almost invisible:

pic1

I tried to add the same list to the activit, everything was displayed as it should:

pic2

The only way out (for now) is to change the color of the background of the list (or the list in which the list is located). But still I would like to achieve a display like in the second screenshot. Thank you in advance!

The layout code in which the list is:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ExpandableListView android:id="@+id/elvMain" android:layout_width="match_parent" android:layout_height="wrap_content"> </ExpandableListView> </LinearLayout> </LinearLayout> 

Fragment code:

 public class ExercisesFragment extends Fragment{ ExpandableListView elvMain; ExercisesAdapter EA; SimpleExpandableListAdapter adapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.exercises_fragment, container, false); EA = new ExercisesAdapter(getActivity()); adapter = EA.getAdapter(); elvMain = (ExpandableListView) rootView.findViewById(R.id.elvMain); //elvMain.setBackgroundColor(getResources().getColor(R.color.black)); elvMain.setAdapter(adapter); return rootView; } } 

ExercisesAdapter code:

 public class ExercisesAdapter { final String ATTR_GROUP_NAME= "groupName"; final String ATTR_EXERC_NAME= "exerName"; // названия Π³Ρ€ΡƒΠΏΠΏ ΡƒΠΏΡ€Π°ΠΆΠ½Π΅Π½ΠΈΠΉ String[] groups = new String[] {"Group 1", "Group 2", "Group 3", "Group 4","Group 5", "Group 6", "Group 7", "Group 8", "Group 9"}; // названия ΡƒΠΏΡ€Π°ΠΆΠ½Π΅Π½ΠΈΠΉ String[] Group1 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; String[] Group2 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; String[] Group3 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; String[] Group4 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; String[] Group5 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; String[] Group6 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; String[] Group7 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; String[] Group8 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; String[] Group9 = new String[] {"Exercise 1", "Exercise 2", "Exercise 3", "Exercise 4", "Exercise 5"}; // коллСкция для Π³Ρ€ΡƒΠΏΠΏ ArrayList<Map<String, String>> groupData; // коллСкция для элСмСнтов ΠΎΠ΄Π½ΠΎΠΉ Π³Ρ€ΡƒΠΏΠΏΡ‹ ArrayList<Map<String, String>> childDataItem; // общая коллСкция для ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΉ элСмСнтов ArrayList<ArrayList<Map<String, String>>> childData; // Π² ΠΈΡ‚ΠΎΠ³Π΅ получится childData = ArrayList<childDataItem> // список Π°Ρ‚Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² Π³Ρ€ΡƒΠΏΠΏΡ‹ ΠΈΠ»ΠΈ элСмСнта Map<String, String> m; Context ctx; ExercisesAdapter(Context _ctx) {ctx = _ctx;} SimpleExpandableListAdapter adapter; SimpleExpandableListAdapter getAdapter() { // заполняСм ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ Π³Ρ€ΡƒΠΏΠΏ ΠΈΠ· массива с названиями Π³Ρ€ΡƒΠΏΠΏ groupData = new ArrayList<Map<String, String>>(); for (String group : groups) { // заполняСм список Π°Ρ‚Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² для ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Π³Ρ€ΡƒΠΏΠΏΡ‹ m = new HashMap<String, String>(); m.put(ATTR_GROUP_NAME, group); // имя Π³Ρ€ΡƒΠΏΠΏΡ‹ groupData.add(m); } // список Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² Π³Ρ€ΡƒΠΏΠΏ для чтСния String groupFrom[] = new String[] {ATTR_GROUP_NAME}; // список ID view-элСмСнтов, Π² ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΠΎΠΌΠ΅Ρ‰Π΅Π½Ρ‹ Π°Ρ‚Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Ρ‹ Π³Ρ€ΡƒΠΏΠΏ int groupTo[] = new int[] {android.R.id.text1}; // создаСм ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ для ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΉ элСмСнтов childData = new ArrayList<ArrayList<Map<String, String>>>(); add(childData, Group1); add(childData, Group2); add(childData, Group3); add(childData, Group4); add(childData, Group5); add(childData, Group6); add(childData, Group7); add(childData, Group8); add(childData, Group9); // список Π°Ρ‚Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² элСмСнтов для чтСния String childFrom[] = new String[] {ATTR_EXERC_NAME}; // список ID view-элСмСнтов, Π² ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΠΎΠΌΠ΅Ρ‰Π΅Π½Ρ‹ Π°Ρ‚Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Ρ‹ элСмСнтов int childTo[] = new int[] {android.R.id.text1}; adapter = new SimpleExpandableListAdapter( ctx, groupData, android.R.layout.simple_expandable_list_item_1, groupFrom, groupTo, childData, android.R.layout.simple_list_item_1, childFrom, childTo); return adapter; } public ArrayList<ArrayList<Map<String, String>>> add(ArrayList<ArrayList<Map<String, String>>> childData, String[] Group ){ // создаСм ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ элСмСнтов для ΠΏΠ΅Ρ€Π²ΠΎΠΉ Π³Ρ€ΡƒΠΏΠΏΡ‹ childDataItem = new ArrayList<Map<String, String>>(); // заполняСм список Π°Ρ‚Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ элСмСнта for (String exercise : Group) { m = new HashMap<String, String>(); m.put(ATTR_EXERC_NAME, exercise); // Π½Π°Π·Π²Π°Π½ΠΈΠ΅ упраТнСния childDataItem.add(m); } // добавляСм Π² ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΉ childData.add(childDataItem); return childData; } } 
  • Unfortunately, none of the tips helped (Instead of ExpandableListView I now use RecycleView - qqdasdzxc
  • Sorry. If you find the answer yourself, please post the found solution in the answer to your question . I am sure it will help many of your colleagues in the future. - Nicolas Chabanovsky ♦

3 answers 3

Set the style for the list items. You apparently textColorPrimary set to white, and that the list of elements with white text. How to ask - it is already google.
In another way, you will not learn how to solve such problems.

    The text color appears to be inherited from the style that you have defined in styles.xml

    As a solution, I can advise you to specify your markup in the Π°Π΄Π°ΠΏΡ‚Π΅Ρ€Π΅

     adapter = new SimpleExpandableListAdapter( ctx, groupData, R.layout.my_expandable_list_item_1, groupFrom, groupTo, childData, R.layout.my_list_item_1, childFrom, childTo); 

    And it already has to change everything your heart desires.

      When I added ExpandedListView to Activate Extend Edition Bar, the font color also began to merge with the white background, just changed the markup as advised ermak0ff Added my_expandable_list_item_1 and my_list_item_1 to the layout folder, There you should be very careful, firstly, as if you didn’t want ctrl-c to get up, I had to slowly and with the markup android.R.layout.simple_expandable_list_item_1 take a view and build my own and how it all got up. Secondly, all the links are correct to set android.R.layout to change to R.layout there in the code these links are not the same. In general, the markup has earned, the font color has changed.