2011-07-03 9 views
0

간단한 사용자 정의 대화 상자를 표시하고 싶습니다. 처음에는 텍스트보기를 추가하고 대화 상자가 표시되는지 확인하기 만했습니다. 사용자가 (나) (가) 나는이 코드를 사용하여 메뉴 항목을 누르면Android 사용자 정의 대화 상자가 표시되지 않습니다.

@Override 
protected Dialog onCreateDialog(int id) { 
    final Dialog dialog = new Dialog(this); 
    dialog.setContentView(R.layout.predialog); 
    dialog.setTitle("Tests of my Dialog"); 
    return dialog; 
} 

: 이것은이 onCreateDialog 기능에 대한 내 코드입니다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<TextView android:id="@+id/tvPreview" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:text="@string/Instructions"></TextView> 
</LinearLayout> 

:

내 XML입니다

public void DiagTests(){ 
    showDialog(0); 
} 

화면이 흐릿하지만 대화 상자가 표시되지 않는 경우가 발생합니다.

내가 뭘 잘못하고 있는지 알 수있는 사람이 있습니까?

경찰 : 어떤 종류의 오류나 경고가없는 경우를 대비하여. 어떤 도움

답변

1

당신은이 방법을 시도해 볼 수도 있습니다에 대한

감사합니다.

final DialogWithSelect dialog = new DialogWithSelect(getContext()); 
dialog.setTitle(R.string.dialogSelectBoxText); 

:

/** Class Must extends with Dialog */ 
/** Implement onClickListener to dismiss dialog when OK Button is pressed */ 
public class DialogWithSelect extends Dialog implements OnClickListener { 

private String _text; 
Button okButton; 
Button cancelButton; 
/** 
* ProgressDialog that will be shown during the loading process 
*/ 
private    ProgressDialog   myDialog; 

public DialogWithSelect getDialog() { 
    return this; 
} 

public String getText() { 
    return this._text; 
} 

public DialogWithSelect(Context context) { 
    super(context); 
    myDialog = new ProgressDialog(this.getContext()); 
    myDialog.setMessage("Exporting file..."); 
    /** 'Window.FEATURE_NO_TITLE' - Used to hide the title */ 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    /** Design the dialog in main.xml file */ 
    setContentView(R.layout.dialog_with_select_box); 

    final Spinner hubSpinner = (Spinner) findViewById(R.id.spinnerSelectFormat); 
    ArrayAdapter adapter = ArrayAdapter.createFromResource(this.getContext(), R.array.spinner , android.R.layout.simple_spinner_item); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    hubSpinner.setAdapter(adapter); 


    okButton = (Button) findViewById(R.id.okButton); 
    cancelButton = (Button) findViewById(R.id.cancelButton); 

     okButton.setOnClickListener(new View.OnClickListener(){ 

      public void onClick(View v) { 
      //whatever 
      } 

     }); 



    cancelButton.setOnClickListener(new View.OnClickListener(){ 

     public void onClick(View v) { 
      //Get the text from the texString to paint on the Canvas 
      getDialog().hide(); 
     } 

    } 
); 


} 

그것을 사용하는 것입니다 클래스에 대화 상자를 정의합니다 (이 클래스의 예를 들어, 당신은 당신이 원하는 것을 사용할 수있다) 사용자 정의 대화 상자 클래스를 만듭니다 클릭 이벤트에서 실행하십시오 :

dialog.show(); 
+0

실제로 작동하도록했습니다. 그러나 그것은 이상했다. 이 사용자 정의 대화 상자를 테스트하기 위해 완전히 새로운 프로젝트를 만들었고 XML을 처음부터 다시 만들지 않았기 때문에 첫 번째 시도에서 작동했습니다. 그래서 내가 한 일은 xml을 처음부터 생성하고 작동했습니다. 도와 주셔서 감사합니다. 그것이 무엇이 잘못되었는지를 아는 것은 매우 흥미롭지 만 ... – aarelovich

관련 문제