1

我想列出数据库中的开关名称,为此我已经实现了Recyclerview列表应用程序。现在,问题是,我的Recyclerview项目包含开关元素,我想在打开或关闭它时执行两个功能。那可能吗?我在小鸡监听器的视图持有者上尝试了它,但它为每个列表元素提供了相同的 id。



    07-07 13:25:29.915 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:30.236 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:30.439 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:30.655 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:30.860 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:31.105 7705-7705/com.sdns.blacksparrow D/你点击了我的id:-1
    07-07 13:25:32.210 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:32.415 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:32.599 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:32.805 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1
    07-07 13:25:32.986 7705-7705/com.sdns.blacksparrow D/你点击了我的ID:-1

4

1 回答 1

1

您可以使用OnCheckedChangeListener

mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // do something, the isChecked will be
    // true if the switch is in the On position
}
});

看到这个答案

于 2016-07-07T09:36:09.390 回答