我有一个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;
}
}
}
任何人都可以帮忙吗?