如何监听列表视图行中的复选框?
String[] from = new String[] { CallrzDbAdapter.C_NAME,CallrzDbAdapter.C_EMAIL,CallrzDbAdapter.C_PHONE };
int[] to = new int[] {R.id.cName, R.id.cEmail, R.id.cPhone };
notes = new SimpleCursorAdapter(this,
R.layout.row, cursor, from, to);
ListView view =getListView();
view.setHeaderDividersEnabled(true);
view.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
view.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View view,
int position, long arg3) {
Toast.makeText(getApplicationContext(), "Hello"+position+" is clicked ",
Toast.LENGTH_SHORT).show();
return false;
}
});
//setListAdapter(notes);
setListAdapter(notes);
我有一个列表行的自定义布局,其中也有一个复选框。如何为复选框事件创建侦听器?我搜索并听说过bindView,但是有人可以更清楚地解释它吗? 此是链接有人解释了它,但我无法将其插入我的代码中。
String[] from = new String[] { CallrzDbAdapter.C_NAME,CallrzDbAdapter.C_EMAIL,CallrzDbAdapter.C_PHONE };
int[] to = new int[] {R.id.cName, R.id.cEmail, R.id.cPhone };
notes = new SimpleCursorAdapter(this,
R.layout.row, cursor, from, to);
ListView view =getListView();
view.setHeaderDividersEnabled(true);
view.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
view.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View view,
int position, long arg3) {
Toast.makeText(getApplicationContext(), "Hello"+position+" is clicked ",
Toast.LENGTH_SHORT).show();
return false;
}
});
//setListAdapter(notes);
setListAdapter(notes);
I have a custom layout for the list row which has a checkbox as well. How can I create a listener for the checkbox event? I have searched and heard about bindView but is there anyone can explain it a bit more clearly? this is the link someone explained it but I couldnt plug it in my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建自己的 ViewBinder 并在 setViewValue 中简单地执行以下操作:
然后您可以使用 SampleAdapter 获取数据并调用
adapter.setViewBinder(new MyViewBinder());
You can probably create your own ViewBinder and in setViewValue simply do something like:
You can thenjust use SampleAdapter for data and call
adapter.setViewBinder(new MyViewBinder());
onItemLongClick
中的view
应包含您的复选框。您可以像平常一样检索它:
如果我错了,请纠正我,我通常使用自定义
ArrayAdapter
编辑:
您可以看一下这个示例。
Android 系列:自定义 ListView 项目和适配器
提示:在示例中的
getView
中,您可以findViewById
您的CheckBox
The
view
fromonItemLongClick
should contain your checkbox.You can retreive it like you normally would:
Correct me if i'm wrong, I normally use a Custom
ArrayAdapter
EDIT:
You could look at this for an example.
Android Series: Custom ListView items and adapters
Hint: it's the
getView
in the example where you canfindViewById
yourCheckBox