我有一个适配器,它扩展了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]);
}
有没有人知道为什么背景在以前选定的项目上消失,或者有时在除了所选项目之外的所有项目上消失 .
2 回答
我认为这是一种错误(或者我并没有真正得到真正的功能) .
无论如何你应该试着打电话
在您的代码中,以便为每个项目执行它 .
最后问题是图像(new_strip) . 我必须像图像(只有白色背景和灰色圆角)制作一个drawable,以便解决问题 .