2011-01-06 6 views
0

두 개의 버튼이있는 편집 텍스트 필드를 사용하여 경고 대화 상자를 동적으로 작성합니다. 대화 상자는, 나는 그것이AlertDialog에서 부모 너비를 채우는 방법

public void showMessageDialog(String name){ 

    final AlertDialog.Builder alert = new AlertDialog.Builder(this); 
    this.etMessage = new EditText(this); 
    etMessage.setText(""); 
    alert.setMessage("Message " + name); 
    alert.setView(etMessage); 
    alert.setPositiveButton("Message", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
      updateLocation(); 

     } 
    }); 
    alert.setNeutralButton("Map", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
      showMap(); 
     } 
    }); 

    alert.show(); 
} 

답변

0

내가 코드에서 그것을 할 방법을 모르는 부모 폭을 채우기 위해 스트레칭하려면 매우 작은 폭을 포장되지만 XML에서보기를 부풀려 경우 최상위보기에 layout_width="fill_parent" 속성을 추가하면 화면을 채워야합니다.

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 

당신은 다음과 같이 뷰 팽창 할 수

View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_view, null); 

을하고에 AlertDialog.Builder에 추가하여 XML에 존재하지 않는

builder.setView(dialogLayout); 
+1

그래,하지만 대화 상자 시트. 대화 요소가 있다고 생각조차하지 않습니다. – Brian

+0

아니요,하지만보기를 인스턴스화하고 AlertDialog.Builder에 추가 할 수 있습니다. 답변을 더 추가하여 나에게 도움을줍니다. –

관련 문제