안드로이드 개발 질문/답변
(글 수 45,052)
AlertDialog class에 대한 질문입니다.
아래와 같이 Alert라는 class를 만들고 호출하도록 만들었습니다.
Alert.show(this, "test", "1");
Alert.show(this, "test", "2");
Alert.show(this, "test", "3");
문제는 AlertDialog 1이 뜬 상태에서 대기하지 않고, 2, 3 계속 뜹니다.
그리고 dialog가 보이는 상태에서 화면을 보면 그 다음에 있는 code가 실행되어 있습니다.
경험있으신 분 조언바랍니다.
public class Alert
{
static public void show (Context context, String title, String message)
{
// build dialog box to display when user clicks the flag
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(false)
.setTitle(title)
.setMessage(message)
.setPositiveButton("Done", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.dismiss();
}
}
);
final AlertDialog alert = builder.create();
alert.show();
}
}
위의 코드를 다르게 수정해 보아도 마찬가지입니다.
아래와 같이 Alert라는 class를 만들고 호출하도록 만들었습니다.
Alert.show(this, "test", "1");
Alert.show(this, "test", "2");
Alert.show(this, "test", "3");
문제는 AlertDialog 1이 뜬 상태에서 대기하지 않고, 2, 3 계속 뜹니다.
그리고 dialog가 보이는 상태에서 화면을 보면 그 다음에 있는 code가 실행되어 있습니다.
경험있으신 분 조언바랍니다.
public class Alert
{
static public void show (Context context, String title, String message)
{
// build dialog box to display when user clicks the flag
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(false)
.setTitle(title)
.setMessage(message)
.setPositiveButton("Done", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.dismiss();
}
}
);
final AlertDialog alert = builder.create();
alert.show();
}
}
위의 코드를 다르게 수정해 보아도 마찬가지입니다.
2010.05.20 13:36:53
c++로 windows용 프로그램을 짜다가 Java, Android를 사용하니 좀 불편하군요. 좋은 점도 잇겟지만..
dismiss listener는 dialog 닫히는 시점에 어떤 일을 하는 것이고, 프로세스를 중단시키고 대기할 수는 없는 것이네요.
다음 코드를 수행하지 않고 대기하고 있다가 dialog가 닫히고 수행하게 할 방법은 없을까요?
dismiss listener는 dialog 닫히는 시점에 어떤 일을 하는 것이고, 프로세스를 중단시키고 대기할 수는 없는 것이네요.
다음 코드를 수행하지 않고 대기하고 있다가 dialog가 닫히고 수행하게 할 방법은 없을까요?
2010.05.21 14:04:59
저도 이 문제 때문에 고민을 좀 했었는데요.. 윈도우에서처럼 block 되야 하는데 안되니 참.. ㅎㅎ
간단하게 해결하시려면 메인 프로세스를 중단시키고 다이얼로그 처리 후 다음 코드를 처리하는 방식을 피하세요.
이건 윈도우와 모바일 환경에서의 설계 자체가 다르니 어쩔 수 없는 부분인 것 같아요..
간단한 해결책은 다음에 실행될 코드를 다이얼로그의 public void onClick(DialogInterface dialog, int id) 이 안에다가 넣는 거에요..
근데 onClick 함수 내에서는 스태틱 변수만 사용할 수 있기 때문에 처리가 제한적이에요..
그래서 처리 메서드를 따로 만들어서 onClick 부분에서는 DialogInterface dialog, int id 이 파라미터들을 인자로 하는(필요없다면 인자는
안 넘겨도 되고요.. ㅎ) 처리 메서드를 호출만 하는 식으로 하고 실제 처리는 다른 메서드에서 실행되도록 하는 거죠..