切换自定义列表视图

时间:2016-04-18 16:22:01

标签: android database listview switch-statement android-cursoradapter

我通过CursorAdapter从包含Switch的SQLite数据库布局填充ListView。

如何监听特定ListItem的Switch更改事件?

1 个答案:

答案 0 :(得分:0)

Register a callback to be invoked when the checked state of this button changes

示例:

mySwitch = (Switch) findViewById(R.id.mySwitch);
// attach a listener to check for changes in a state
mySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
    boolean isChecked) {
    // do something on event
 }
});

同时检查viewholder pattern