Custom list clicking with checkboxes

好久不见. 提交于 2019-11-30 13:36:44
Josef Pfleger

As explained here, the click listener only works if no other view is focusable. Setting your CheckBox to focusable="false" should do the trick:

<CheckBox android:focusable="false" />

Looks like SimpleCursorAdapter is too primitive for what I wanted to achieve. I've switched to implementing CursorAdapter and returning a new view using the LayoutInflater in my implementation of the newView method.

  public View newView(Context context, Cursor cursor, ViewGroup parent) {
    return LayoutInflater.from(context).inflate(R.layout.alarm_row, parent, false);
  }

In bindView I then set a custom OnClickListener to my main LinearLayout and then another OnCheckedChangeListener to the CheckBox.

For all this to look right I had to set the LinearLayout's background to android's menuitem drawable:

android:background="@android:drawable/menuitem_background"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!