我有一个:复选框不改变状态
public class MyList extends ListActivity {
SimpleAdapter simpleAdapter;
结合ListView
被做了ViewBinder
:
simpleAdapter = new SimpleAdapter(this, getData(path),
R.layout.menu_row, new String[] {
..., "checked" }, new int[] {..., R.id.checkBox1 });
SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if (view.getId() == R.id.checkBox1) {
CheckBox checkBox = (CheckBox) view;
checkBox.setChecked(Boolean.parseBoolean((String) data));
我的XML看起来像这样,clickable
和focusable
有助于该行表现为一个。
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
/>
我也有一个:
protected void onListItemClick(ListView l, View v, int position, long id) {
与click事件交互。这个效果很好,我的问题是 当我点击一行时,CheckBox
不会改变它的视觉状态。我能做什么?
谁是按钮? 我有的是 \t保护无效onListItemClick(ListView的升,视图V,INT位置,长ID){ \t \t 复选框\t复选框=(复选框)v.findViewById(R.id.checkBox1); checkbox.setChecked(!checkbox.isChecked()); 但它显示没有效果 – user1324936
对不起,意思是复选框。即使图形不是,您是否可以确认状态正在改变?你有没有尝试notifyDatasetChanged(我认为我有这个权利,我:我的手机上,远离资源) – Barak
是的,我打电话给simpleAdapter.notifyDataSetChanged(); 这是问题所在:它调用getData方法,该方法不知道任何复选框更改。我评论说,谢谢你的想法带来了我的错误 – user1324936