我想列出数据库中的交换机名称,为此我已经为Recyclerview
列表实现了应用程序。现在,问题是,我的Recyclerview
项包含switch元素,我想在打开或关闭它时执行两个函数。那可能吗?我在小鸡监听器上的视图持有者上尝试过它,但它为每个列表元素提供了相同的id。
07-07 13:25:29.915 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:30.236 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:30.439 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:30.655 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:30.860 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:31.105 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:32.210 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:32.415 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:32.599 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:32.805 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1 07-07 13:25:32.986 7705-7705/com.sdns.blacksparrow D/you clicked my id: -1
答案 0 :(得分: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
}
});
请参阅this answer