gpt4 book ai didi

android - 如何在 Android 2.3.3 的 ListView 中突出显示选定的行。 (HoloeveryWhere + ABS)

转载 作者:行者123 更新时间:2023-11-30 03:30:16 24 4
gpt4 key购买 nike

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 是

<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>

在模拟器(android 2.3.3)中,当 ListView 接近出现在屏幕上时,我有下一个异常:

 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)

如果我从代码中删除 getListView().setSelector(R.drawable.activated_background);,并将其移动到 XML 中作为我列表自定义行的背景:

<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>

它在 4+ 中工作,但在 2.3 中,选定的行不会毫无异常(exception)地突出显示。

欢迎任何帮助。

最佳答案

我在这上面花了 1 天多的时间,最后我开始使用这个愚蠢的决定:

@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));
}

也许有人知道如何以更“正常”的方式解决它?

关于android - 如何在 Android 2.3.3 的 ListView 中突出显示选定的行。 (HoloeveryWhere + ABS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17576716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com