2016-06-12 3 views
0

안드로이드에서 대화 상자를 작성하려고하지만 메서드를 호출 한 후에 대화 상자가 나타나지 않습니다.메서드 호출 후 대화 상자가 나타나지 않습니다.

이 내가 방법을 선언하는 방법입니다

public Dialog onCreateDialog() { 
    // Use the Builder class for convenient dialog construction 
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
    builder.setMessage("testing") 
      .setPositiveButton("COPY TO", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        // do something 
       } 
      }) 
      .setNegativeButton("MOVE TO", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        //do something 
       } 
      }); 
    // Create the AlertDialog object and return it 
    return builder.create(); 
} 

이 내가 메서드를 호출하는 방법입니다

for (int i = 0; i < lvMain.getChildCount(); i++) { 
      LinearLayout itemLayout = (LinearLayout) lvMain.getChildAt(i); 
      final CheckBox cb = (CheckBox) itemLayout.findViewById(R.id.cbBox); 
      cb.setVisibility(View.VISIBLE); 
      cb.setChecked(true); 
      onCreateDialog(); 
     } 

어떤 생각이 왜 작동하지 않습니다?

답변

1

깜빡했다고 생각합니다. .show();

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
    builder.setMessage("testing") 
      .setPositiveButton("COPY TO", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        // do something 
       } 
      }) 
      .setNegativeButton("MOVE TO", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        //do something 
       } 
      }).show(); 
} 
+0

정말 고마워요! – purplewind

관련 문제