1
如何更改toggleButton的状态只有在单击对话框上的确定后,如果我单击取消toggleButton没有更改,我的问题是toggleButton总是切换,那么是否有示例或特定需要在之前完成的实现?ToggleButton状态OnClick
toggle1 = (ToggleButton) findViewById(R.id.filterButton);
// toggle1.setChecked(getDefaults("Toggle1S",this));
// setDefaults("Toggle1S", toggle1.isChecked(), this);
toggle1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if (toggle1.isChecked()) {
on.start();
Using();
if(Use.equals("1"))
{//Wifi Function
Toast.makeText(getApplicationContext(), "Filter ON sent using Wifi", Toast.LENGTH_SHORT).show();
new MyAsyncTask().execute("filter_st","ON");
}
else{
String temp = "Are you want to turn Filter ON using GSM";
callCheck(SMStitle,temp);
sm.sendTextMessage(number, null, messages[0], null, null);
Toast.makeText(getApplicationContext(), "Filter ON sent using GSM number"+number, Toast.LENGTH_SHORT).show();
}
public void callCheck(String c,String d)
{
// Creating alert Dialog with one Button
AlertDialog alertDialog1 = new AlertDialog.Builder(
fishtank.this).create();
// Setting Dialog Title
alertDialog1.setTitle(c);
// Setting Dialog Message
alertDialog1.setMessage(d);
// Setting OK Button
alertDialog1.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Toast.makeText(getApplicationContext(),"You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
alertDialog1.setButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// Showing Alert Message
alertDialog1.show();
}
您发布的代码缺少右括号,特别是在您的第一个onClick方法。这是否编译? –
不,我删除了所有内容,并保留了该问题的部分,因为我只需要至少一个示例:D – user1928775