2014-06-17 6 views
0

알림 대화 상자를 만들려고 시도하지만 애플리케이션을 실행할 때 표시되지 않습니다. 여기에 내 코드는 다음과 같습니다Android 앱의 AlertDialog가 표시되지 않습니다.

final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
    builder.setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
     public void onClick(final DialogInterface dialog, final int id) { 
      startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); 
     } 
    }).setNegativeButton("No", new DialogInterface.OnClickListener() { 
     public void onClick(final DialogInterface dialog, final int id) { 
      dialog.cancel(); 
      buildLocationMessage(); 
     } 
    }); 
    final AlertDialog alert = builder.create(); 
    alert.show(); 

답변

0

이 시도 :

final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
     alertDialog.setTitle(title); 
     alertDialog.setMessage(message); 

     alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       alertDialog.dismiss(); 
      } 
     }); 
     alertDialog.show(); 

그냥이 코드를 시도

+0

아직 아무것도. 또한 setButton 메서드가 더 이상 사용되지 않는다는 경고가 나타납니다. –

0

"아니오"의 setButton를 추가 -

final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 

builder.setMessage("Your GPS seems to be disabled,do you want to enable it?"); 

builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 

public void onClick(DialogInterface dialog, int whichButton) { 

//do stuff 
startActivity(
    new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); 
    } 
}); 

builder.setNegativeButton("No", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int id) { 
     dialog.cancel(); 
    } 
}); 

AlertDialog alert = builder.create(); 
alert.show(); 
+0

작동하지 않았습니다. 이것은 본질적으로 동일한 코드입니다. 네가 만든 변화를 놓친 것인지 궁금해! –

+0

최근에 변경했습니다. 위의 최신 업데이트를 사용해보십시오. –

+0

네, 편집을보고 사용했습니다. 정말 이상한 점은, 이것이 이전에 사용했던 코드와 기본적으로 동일하지만, 지금은 다른 곳에서 작동하지 않는다는 것입니다. –

관련 문제