У меня есть 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;
}
}
}
Может кто-нибудь помочь?