在开发Android应用时,我不想在setChecked
方法中进行回调。
相反,我想使用带有切换按钮来实现此目的。
以下是我的代码: XXAdapter(ListView)
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MHolder holder;
if (convertView == null) {
convertView = this.inflater.inflate(layout, null);
holder = new MHolder();
holder.toggleButton = (ToggleButton) convertView
.findViewById(R.id.my_toggle);
holder.toggleButton
.setOnCheckedChangeListener(listener);
convertView.setTag(holder);
}
MParam param = params.get(position);
holder = (MHolder) convertView.getTag();
ToggleButton toggle = holder.toggleButton;
toggle.setChecked(false);
if (param.state == 2)
toggle.setChecked(true); // here
return convertView;
}
如何在切换按钮更改标志上设置回调方法?
答案 0 :(得分:0)
如果不想采取行动,请不要使用此行
holder.toggleButton
.setOnCheckedChangeListener(listener);
答案 1 :(得分:0)
您是否检查过setOnCheckedChangeListener
ToggleButton
toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(arg1){
// toggleButton is checked
}else{
// toggleButton is unchecked
}
}
});