【发布时间】:2011-01-17 23:10:11
【问题描述】:
我有一个自定义可绘制资源来在 ListView 中显示我的项目,实际上是两个,因为我希望我的结果具有交替的背景颜色,但两者都通过更改颜色来响应点击。问题是即使通过布局 XML 将这些可绘制对象中的一个分配给我的 LinearLayout 容器,它也可以正常工作,但通过 Java 代码却不能。确切地说,这是可行的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/result_white"
android:id="@+id/result"
>
但是这个(在我扩展 ArrayAdapter 的 ResultAdapter 中)没有:
LinearLayout result = (LinearLayout) v.findViewById(R.id.result);
result.setBackgroundColor(R.drawable.result_white);
我的最终目标当然是为结果交替使用“result_white”和“result_ltgray”可绘制对象,因此第一个 XML 解决方案并不能真正满足我的需求。请问我在 Java 代码中遗漏了什么?
【问题讨论】:
标签: android listview drawable listactivity