gpt4 book ai didi

java - 多路开关中开关盒的解决方案

转载 作者:行者123 更新时间:2023-12-02 02:31:50 25 4
gpt4 key购买 nike

在此代码中

CompoundButton.OnCheckedChangeListener multiListener = new CompoundButton.OnCheckedChangeListener() {

public void onCheckedChanged(CompoundButton v, boolean isChecked) {
switch (v.getId()){
case R.id.msg:
startActivity(new Intent(Mainfunction.this, Get_messages.class));
break;
case R.id.cnt:
Toast.makeText(Mainfunction.this, "Contact In Procces", Toast.LENGTH_SHORT).show();
break;
case R.id.call:
startActivity(new Intent(Mainfunction.this, Get_callLog.class));
break;
case R.id.loc:
Toast.makeText(Mainfunction.this, "Location In Procces", Toast.LENGTH_SHORT).show();
break;
case R.id.ring:
Toast.makeText(Mainfunction.this, "Ringing In Proccess", Toast.LENGTH_SHORT).show();
break;
}
}
};

//on each switch
((Switch) findViewById(R.id.msg)).setOnCheckedChangeListener(multiListener);
((Switch) findViewById(R.id.cnt)).setOnCheckedChangeListener(multiListener);
((Switch) findViewById(R.id.call)).setOnCheckedChangeListener(multiListener);
((Switch) findViewById(R.id.loc)).setOnCheckedChangeListener(multiListener);
((Switch) findViewById(R.id.ring)).setOnCheckedChangeListener(multiListener);

在开关情况下,我的 Intent Activity Get_messagesGet_callLog 将在我打开或关闭时调用,但我只想在打开时调用什么可以我愿意??

最佳答案

如果您只想在选择该项目时执行某些操作,则可以将整个 switch 语句包装在 if 中:

public void onCheckedChanged(CompoundButton v, boolean isChecked) {
if (isChecked) {
switch (v.getId()){
// cases go here
}
}
}

关于java - 多路开关中开关盒的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46967472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com