0
我有一個AlertDialog
提示用戶是否想要發送數據。我正在做的是檢查是否有互聯網連接,如果沒有,我會再次顯示對話框。 對話框會顯示,但是當我點擊「是」時,連接關閉時它不會顯示相同的對話框。在AlertDialog中調用相同的AlertDialog
public void sendData(){
boolean connected = checkConnectivity(getApplicationContext());
//connected is false, but dialog doesnt show the second time.
if(connected==false){
//show dialog
showDialog(0);
}else{
//connected, send data
}
}
@Override
protected Dialog onCreateDialog(int id)
{
return
new AlertDialog.Builder(this)
.setTitle("Send data?")
.setPositiveButton("Yes", new DialogButtonClickHandler())
.setNegativeButton("No", new DialogButtonClickHandler())
.create();
}
public class DialogButtonClickHandler implements DialogInterface.OnClickListener
{
public void onClick(DialogInterface dialog, int clicked)
{
switch(clicked)
{
case DialogInterface.BUTTON_POSITIVE:
//Problem occurs here. sendData() gets called but dialog not displayed the second time
sendData();
break;
case DialogInterface.BUTTON_NEGATIVE:
return;
}
}
}
任何人都可以幫忙嗎?