Zaznacz wybraną pozycję na rozwijalnej liście
Mam układ, w którym mam rozwijaną listę we fragmencie po lewej stronie i fragment po prawej stronie. To wszystko działa dobrze.
Teraz chciałbym wskazać, który element po lewej stronie ma swoje szczegóły pokazane po prawej stronie i tutaj mam problem.
W normalnym widoku listy osiągnąłem to, ustawiając tryb wyboru dla widoku listy na pojedynczy, a następnie wykorzystując stan do wyciągnięcia w oparciu o stan „aktywowany”. Kiedy klikam element, tło jest ustawiane na mój wybrany kolor i pozostaje w tym stanie do momentu wybrania innego elementu na liście.
Próbowałem zastosować to do mojego rozwijanego widoku listy i to było / jest ponurą porażką. Nie było błędów, ale wybrany element nie zachował stanu koloru. Nie jestem pewien, czy właściwie ustawię dla niego tryb wyboru (wypróbowałem go zarówno w pliku układu, jak i programowo, nie wydaje się, aby coś zmieniło) lub wskazywał na niewłaściwą rzecz (nie wiesz, jak to możliwe, ale ...)
Każda pomoc / wskazówki są doceniane (nawet jeśli jest to zupełnie inny kierunek).
Najbardziej aktualna awaria:
rozszerzalny kod listview
<code>private void fillData(String group, String child) { ExpandableListView lv; mGroupsCursor = mDbHelper.fetchGroup(group); getActivity().startManagingCursor(mGroupsCursor); mGroupsCursor.moveToFirst(); lv = (ExpandableListView) getActivity().findViewById(R.id.explist); lv.setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE); mAdapter = new MyExpandableListAdapter(mGroupsCursor, getActivity(), R.layout.explistlayout, R.layout.explistlayout, new String[] { "_id" }, new int[] { android.R.id.text1 }, new String[] { child }, new int[] { android.R.id.text1 }); lv.setAdapter(mAdapter); registerForContextMenu(lv); lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { mRowId = id; EventDisplayFragment eventdisplay = new EventDisplayFragment(); getFragmentManager().beginTransaction().replace(R.id.rightpane, eventdisplay).commit(); return true; } }); } public class MyExpandableListAdapter extends SimpleCursorTreeAdapter { public MyExpandableListAdapter(Cursor cursor, Context context, int groupLayout, int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom, int[] childrenTo) { super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childrenFrom, childrenTo); } @Override protected Cursor getChildrenCursor(Cursor groupCursor) { Cursor childCursor = mDbHelper.fetchChildren(mGroup, groupCursor .getString(groupCursor .getColumnIndex(AttendanceDB.EVENT_ROWID))); getActivity().startManagingCursor(childCursor); childCursor.moveToFirst(); return childCursor; } } </code>
item_selector.xml
<code><?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@color/green" /> <item android:state_selected="true" android:drawable="@color/blue" /> <item android:state_focused="true" android:drawable="@color/violet" /> <item android:state_activated="true" android:drawable="@color/blue" /> </selector> </code>