마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

다이얼로그 관련해서 궁금한 점이 있습니다.

0 추천

 

안녕하세요.

다이얼로그 관련해서 궁금한 점이 있습니다.

제가 다이얼로그 관련해서 자바클래스와 xml 파일 관련해서 각각 1개씩 만들었습니다.

그리고 다이얼로그가 출력되는 것에 이상이 없습니다.

그런데, 이와 같은 다이얼로그를 여러개 내용을 다르게 주고 출력을 해주고 싶은데 그럴 때 마다 각각

1개의 클래스와 1개의 xml을 계속적으로 추가를 시켜주어야 하는건가요 ..? 이 부분이 너무 알고 싶습니다.

 

자바 부분의 소스코드는 아래와 같습니다. 그리고 xml 의 소스는 문자열 제한으로 인해 댓글 부분에 달아보겠습니다.

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class Custom_Dialog extends Dialog implements View.OnClickListener {

    Button btn;

    public Custom_Dialog(Context context) {
        super(context);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_custom__dialog);

        btn = (Button) findViewById(R.id.Custom_Button);
        btn.setOnClickListener(this);
    }


    public void onClick(View view) {
        if (view.getId() == R.id.Custom_Button) {
            if (isShowing()) {
                dismiss();
            }
        }
    }
}
공산당 (1,960 포인트) 님이 2016년 11월 19일 질문
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_custom__dialog"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#363636"
  >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <TextView
            android:id="@+id/Custom_TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:textColor="#ffffff"
            android:textSize="17dp"
            android:text="@string/Question"
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true"
            />

        <Button
            android:id="@+id/Custom_Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_alignParentRight="true"
            android:text="확인"
            android:background="@drawable/reservaton_round_button"
            android:layout_below="@+id/Custom_TextView"
             />

    </RelativeLayout>

</RelativeLayout>

1개의 답변

0 추천
 
채택된 답변
다이얼로그에서 표현해야할 레이아웃의 형태가 다르다면 화면마다 레아이웃을 다르게 짜야 겠지요.

물론 레이아웃을 짤때 xml 리소스로 안하고 java 코드만으로도 가능은 합니다.(질문하신 의도가 이거는 아니겠지만요.)

만약 제한적인 상황으로 1개의 xml 레이아웃으로만 사용해야 한다면 트릭으로 필요없는것은 GONE 시키고 필요한 것만 VISIBLE 시키는 식으로 하셔도 무방하지만 레이아웃 리소스에 쓸데없는 위젯이 존재하는 만큼 이를 직접적으로 핸들링 하지 않더라도 오버헤드가 되기때문에 되도록 필요한 리소스만 딱 정의해서 쓰는것이 바람직합니다.
Development Guy (70,570 포인트) 님이 2016년 11월 21일 답변
공산당님이 2016년 11월 26일 채택됨
...