自定义列表点击与复选框 [英] Custom list clicking with checkboxes

查看:169
本文介绍了自定义列表点击与复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经填充一个 ListActivity 光标使用 SimpleCursorAdapter 启动另一个活动时,列表项目之一,已被点击。我还使用 ViewBinder 做一些数据的自定义转换。

I've populated a ListActivity from a Cursor using SimpleCursorAdapter that starts another activity when one of the list items have been clicked. I'm also using ViewBinder to do some custom transformation of the data.

我想一个复选框添加到列表中的每一行,所以我改变了我的看法,并添加了复选框重力权利。

I want to add a CheckBox to each row in the list so I've changed the view and added a CheckBox with gravity right.

添加复选框已删除点击该项目的能力。当您在$列表物品P $ PSS中的 onListItemClick 的方法,我在覆盖 ListActivity 不再调用。删除复选框修正了这个。这是为什么?

Adding the CheckBox has removed the ability to click on the items. The onListItemClick method I was overriding in ListActivity is no longer called when you press on a list item. Removing the CheckBox fixes this. Why is this?

另外,我怎么可以设置列表,以便继续执行我的要求的功能,如果该列表项的主要部分被点击,但有附加功能时,复选框在该项目的检查?将设置一个 onCheckedChangedListener 工作或重复使用列表中的每个项目?

Also, how can I set up the list so that it continues to perform my required functionality if the main part of the list item is clicked but have additional functionality when the CheckBox in the item is checked? Will setting a onCheckedChangedListener work or is the same view instance reused for each item in the list?

推荐答案

看起来 SimpleCursorAdapter 是太原始了我想要的东西来实现。 我已经切换到实施的CursorAdapter 并返回使用 LayoutInflater 在我实施<$ C $的新视角C> NewView的方法。

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);
  }

在bindView我再设置一个自定义的 OnClickListener 来我的主要的LinearLayout ,然后另一个 OnCheckedChangeListener 复选框

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

有关这一切看的权利,我不得不设置的LinearLayout 的背景Android的菜单项绘制:

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"

这篇关于自定义列表点击与复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆