[英]ListView android looses background color
我有一个适配器,它可以扩展ArrayAdapter>填充片段布局,每次都有多个选择。 问题在于,有时某些之前选择的项目或所有其他项目的背景会完全消失。 如果您查看此图片http://i.imgur.com/S1KEfM1.png
您会看到ccc选项丢失了背景。 布局会扩大此相对布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="67dp"
android:background="@drawable/selectable_background_example"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical"
android:paddingLeft="20dp"
android:paddingRight="10dp" >
具有此背景的xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:drawable="@drawable/list_focused_example" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/pressed_background_example" android:state_pressed="true"/>
<item android:drawable="@drawable/pressed_background_example" android:state_selected="true"/>
<item android:drawable="@drawable/pressed_background_example" android:state_activated="true"/>
<item android:drawable="@drawable/new_strip"/>
</selector>
Pressed_background_example
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/pressed_example" />
<stroke
android:width="3dp"
android:color="@color/pressed_example" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
</shape>
Pressed_example
<resources>
<color name="pressed_example">#CCCC0000</color>
</resources>
而且new_strip基本上只是带有边框的白色背景图像,而list_focused_example是选中复选框的图像。
我班的GetView
public View getView(int position, View convertView, ViewGroup parent) {
Holder mhHolder;
if (convertView == null) {
mhHolder = new Holder();
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_a, parent, false);
mhHolder.txtValue = (TextView) convertView.findViewById(R.id.txtValue);
mhHolder.txtCheckbox = (CheckBox) convertView.findViewById(R.id.checkBox1);
mhHolder.txtText = (TextView) convertView.findViewById(R.id.txtText);
convertView.setTag(mhHolder);
} else {
mhHolder = (Holder) convertView.getTag();
}
HashMap<String, String> hm = values.get(position);
mhHolder.txtValue.setText(hm.get("Value"));
mhHolder.txtText.setText(hm.get("Text"));
mhHolder.txtCheckbox.setVisibility(View.VISIBLE);
//TODO CHANGE WHEN CHECKED IS SEND
mhHolder.txtCheckbox.setChecked(Base.checked[position]);
}
是否有人对为什么以前选定的项目或有时除选定项目之外的所有项目都没有显示背景有任何线索。
我认为这是一种错误(或者我真的没有真正的功能)。
无论如何,您应该尝试致电
mhHolder.txtValue.setbackground(R.drawable.selectable_background_example);
在您的代码中,以便针对每个项目执行该代码。
最后,问题是图像(new_strip)。 我必须使一个可绘制的图像与该图像相同(它只有白色背景和灰色圆角),以便解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.