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