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;
}
}
}
誰でも助けることができますか?