XML:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
JAVA:
import org.holoeverywhere.app.ListFragment;
import org.holoeverywhere.widget.ListView;
....
....
private void listViewInit() {
getListView().setOnItemClickListener(this);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
getListView().setMultiChoiceModeListener(getMultiChoiceModeListener());
getListView().setSelector(R.drawable.activated_background); // Error there
setListAdapter(adapter);
}
Activated_background is
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@color/row_activated"/>
<item android:drawable="@android:color/transparent"/>
</selector>
In emulator (android 2.3.3) I have next exception when ListView near to appear on screen:
E/AndroidRuntime: FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: File res/drawable/activated_background.xml from drawable resource ID #0x7f020131
at org.holoeverywhere.drawable.DrawableCompat.loadDrawable(DrawableCompat.java:138)
at org.holoeverywhere.drawable.DrawableCompat.getDrawable(DrawableCompat.java:107)
at org.holoeverywhere.widget.ListView.setSelector(ListView.java:954)
at org.kidinov.unixadmin.FileManagerFragment.init(FileManagerFragment.java:211)
at org.kidinov.unixadmin.FileManagerFragment.go(FileManagerFragment.java:183)
at org.kidinov.unixadmin.FileManagerFragment.onResume(FileManagerFragment.java:97)
at android.support.v4.app.Fragment.performResume(Fragment.java:1503)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:948)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1089)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1445)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1c/d=0x0 a=2 r=0x7f090011}
at org.holoeverywhere.drawable.DrawableCompat.loadDrawable(DrawableCompat.java:128)
at org.holoeverywhere.drawable.DrawableCompat.getDrawable(DrawableCompat.java:107)
at org.holoeverywhere.drawable.StateListDrawable.inflate(StateListDrawable.java:194)
at org.holoeverywhere.drawable.DrawableCompat.createFromXmlInner(DrawableCompat.java:87)
at org.holoeverywhere.drawable.DrawableCompat.createFromXml(DrawableCompat.java:63)
at org.holoeverywhere.drawable.DrawableCompat.loadDrawable(DrawableCompat.java:135)
if I deleting getListView().setSelector(R.drawable.activated_background);
from code, and move it in XML as background of custom row of my list:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/activated_background">
....
</RelativeLayour>
it works in 4+, but in 2.3 selected rows do not highlighting without any exceptions.
Any help are welcome.
I spent more than 1 day on this, and at the end I've started to use this stupid decision:
@Override
public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
if (b)
listView.getChildAt(i).setBackgroundColor(activity.getResources().getColor(R.color.row_activated));
else
listView.getChildAt(i).setBackgroundColor(activity.getResources().getColor(R.color.abs__background_holo_dark));
}
Maybe somebody knows how to solve it in more "normal" way?