2012-06-28 7 views
0

라디오 그룹으로 두 개의 라디오 버튼과 "실행"버튼이 있습니다. 라디오 버튼을 선택하고 "실행"을 누르고 라디오 선택에 따라 대체 대화 상자를 보냅니다. 나는에 오류가 마지막에서 두 번째 라인 (경고 대화 상자 빌더를 생성) 다음왜이 변수를 "해결할 수 없습니까?"

private OnClickListener myClickcalcHandler = new OnClickListener() { 
    public void myClickcalcHandler(View view) { 
     switch (view.getId()) { 
     case R.id.calcbutton: 
      RadioButton insideButton = (RadioButton) findViewById(R.id.radioButton1); 
      RadioButton outsideButton = (RadioButton) findViewById(R.id.radioButton1); 
      } 
     if 
     (outsideButton.isChecked()){ 
      //do what you want 
      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
         context); 
       // set title 
       alertDialogBuilder.setTitle("some outside activity"); 
       button = (Button) findViewById(R.id.emailbutton); 
       // set dialog message 
       alertDialogBuilder 
        .setMessage(R.string.email_long) 
        .setCancelable(false) 
        .setNegativeButton("Close",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(); 
         } 
        }); 
     } 
     else if 
     (insideButton.isChecked()){ 
      //do what you want 
      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
        context); 
      // set title 
      alertDialogBuilder.setTitle("some inside activity"); 
      button = (Button) findViewById(R.id.emailbutton); 
      // set dialog message 
      alertDialogBuilder 
        .setMessage(R.string.email_long) 
        .setCancelable(false) 
        .setNegativeButton("Close",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(); 

      } 

그래서 일식 편집기는 그냥 "alertDialogBuilder가 해결 될 수 없다"라고, 나는 이유를 알고하지 않습니다 .

private OnClickListener myClickcalcHandler = new OnClickListener() { 
    public void myClickcalcHandler(View view) { 
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
         context); 

     switch (view.getId()) { 
     case R.id.calcbutton: 
      RadioButton insideButton = (RadioButton) findViewById(R.id.radioButton1); 
      RadioButton outsideButton = (RadioButton) findViewById(R.id.radioButton1); 
      } 
     //YOUR CODE HERE..... 

답변

0

decalare에 AlertDialog는 전 세계적으로 바깥을 의미합니다. 이처럼

:

AlertDialog.Builder alertDialogBuilder; 
    if 
    (outsideButton.isChecked()){ 
     //do what you want 
     alertDialogBuilder = new AlertDialog.Builder(
        context); 
     // ... 
    } 
    else if 
    (insideButton.isChecked()){ 
     //do what you want 
     alertDialogBuilder = new AlertDialog.Builder(
       context); 
     // ... 
    } 
     // create alert dialog 
     AlertDialog alertDialog = alertDialogBuilder.create(); 
     // show it 
    alertDialog.show(); 
+0

로 - 프롬프트 응답에 대한 감사 - 나는 // 여전히 이러한 모든하고 "해결 될 수없는"수를 시도했다 경고 대화 상자 만들기 \t \t \t AlertDialog alertDialog = alertDialogBuilder.create(); - 복사 된 섹션 위의 스크립트에서 alertDialogBuilder를 사용했다는 것이 중요한지 확실하지 않지만 여러 번 사용할 수 있다고 가정합니다. –

0

그런 다음 내에서 정의의 if/else 구조의 AlertDialog.Builder alertDialogBuilder 외부를 선언해야합니다/다른 블록으로 경우

0

이렇게하는 경우 다른 전.

AlertDialog.Builder alertDialogBuilder = null; 

및 교체하여 하이는

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); 

alertDialogBuilder = new AlertDialog.Builder(context); 
+0

안녕하세요 - 신속한 답장을 보내 주셔서 감사합니다. -이 모든 것을 시도했지만 // 경고 대화 상자에서 "해결할 수 없습니다"라는 메시지가 나타납니다. AlertDialog alertDialog alertDialog = alertDialogBuilder.create(); - 복사 된 섹션 위의 스크립트에서 alertDialogBuilder를 사용했다는 것이 중요한지 확실하지 않지만 여러 번 사용할 수 있다고 가정합니다. - –

+0

문제가 계속되면 사용중인 새 코드와 오류가있는 행 및 오류 내용을 게시하십시오. – Eric

관련 문제