2012-11-21 11 views
-3
public void showAlertDialog(Context context, String title, String message, Boolean status) { 

    AlertDialog alertDialog = new AlertDialog.Builder(context).create(); 

    // Setting Dialog Title 
    alertDialog.setTitle(title); 

    // Setting Dialog Message 
    alertDialog.setMessage(message); 

    if(status != null) 
     // Setting alert dialog icon 
     alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail); 
+2

당신이 점점 오류를 게시 할 수 :

 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( context); // set title alertDialogBuilder.setTitle("Your Title"); // set dialog message alertDialogBuilder .setMessage("Click yes to exit!") .setCancelable(false) .setPositiveButton("Yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity MainActivity.this.finish(); } }) .setNegativeButton("No",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); 

이 예는 어떻게 안드로이드에 AlertDialog를 사용하는 알린다? LogCat에서 오류를 붙여 넣기 만하면됩니다. –

+1

"오류"란 무엇입니까? 질문을 수정하십시오. –

+0

오류 게시 ... !!!!!!! 작동하지 않거나 예외가 발생하고 있습니까? –

답변

1

작동하지 않는 것은 아니지만 대화 상자가 나타나지 않는다고 생각합니다.

빌드가 완료되면 alertDialog.show()으로 전화해야합니다.

+0

가장 큰 문제와 해결책. – jeet

+0

내가 분명히 말해 줄 수 있니? – vinya

+1

어떻게 그렇게 명확하지 않습니까? * 문서 * – njzk2

0

LogCat 또는 이와 유사한 기능이 없으면 오류를 찾기가 어렵습니다. 당신은에 AlertDialog를 사용하는 방법을 볼 수 http://www.mkyong.com/android/android-alert-dialog-example/

+0

에 대한 답변을 주셔서 감사합니다. alertDialog.setIcon ((status)? R.drawable.success) : R.drawable.fail); – vinya

+0

"alertDialog.setIcon ((status)? R.drawable.success : R.drawable.fail)"줄에 오류가 발생합니다. 게다가. "성공은 해결할 수 없거나 분야가 아닙니다"라고 말하면 실패라고 말합니다. – alex9311

+0

존재 여부를 확인해야합니다. – secretlm

관련 문제