평소에 다이얼로그를 만들면셔 불편한 점이 있었다. 그것은 내가 원하는데로 디자인을 할줄 몰랐다는 것이다. 구글 오픈 소스를 보면서 액티비티를 이용해서 다이얼로그를 만드는 법을 알아냈다.

@Override
protected Dialog onCreateDialog(int id) {
if (id == WELCOME_DIALOG) {
mWelcomeDialog = new WelcomeDialog(this, this);
mWelcomeDialog.setOnCancelListener(this);
return mWelcomeDialog;
} else if (id == GAME_OVER_DIALOG) {
mGameOverDialog = new GameOverDialog(this, this);
mGameOverDialog.setOnCancelListener(this);
return mGameOverDialog;
}
return null;
}
public class WelcomeDialog extends Dialog implements View.OnClickListener {
private final NewGameCallback mCallback;
private View mNewGame;
public WelcomeDialog(Context context, NewGameCallback callback) {
super(context);
mCallback = callback;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.app_name);
setContentView(R.layout.welcome_dialog);
mNewGame = findViewById(R.id.newGame);
mNewGame.setOnClickListener(this);
}
/** {@inheritDoc} */
public void onClick(View v) {
if (v == mNewGame) {
mCallback.onNewGame();
dismiss();
}
}
}
이 정도만 보면 어느 정도 이해는 가능할 것 같다. 좀 더 자세한 자료는 구글에서 DivideAndConquer 를 참조하자.
@Override
protected Dialog onCreateDialog(int id) {
if (id == WELCOME_DIALOG) {
mWelcomeDialog = new WelcomeDialog(this, this);
mWelcomeDialog.setOnCancelListener(this);
return mWelcomeDialog;
} else if (id == GAME_OVER_DIALOG) {
mGameOverDialog = new GameOverDialog(this, this);
mGameOverDialog.setOnCancelListener(this);
return mGameOverDialog;
}
return null;
}
public class WelcomeDialog extends Dialog implements View.OnClickListener {
private final NewGameCallback mCallback;
private View mNewGame;
public WelcomeDialog(Context context, NewGameCallback callback) {
super(context);
mCallback = callback;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.app_name);
setContentView(R.layout.welcome_dialog);
mNewGame = findViewById(R.id.newGame);
mNewGame.setOnClickListener(this);
}
/** {@inheritDoc} */
public void onClick(View v) {
if (v == mNewGame) {
mCallback.onNewGame();
dismiss();
}
}
}
이 정도만 보면 어느 정도 이해는 가능할 것 같다. 좀 더 자세한 자료는 구글에서 DivideAndConquer 를 참조하자.
'안드로이드' 카테고리의 다른 글
NDK , 문서 번역, OVERVIEW.TXT (0) | 2010.09.16 |
---|---|
Enable or not, BroadcastReceiver (0) | 2010.09.12 |
쉽게 Dialog 만들기.. (0) | 2010.07.28 |
스크롤이 맨 아래에 갔을 때 이벤트 주는 법 (0) | 2010.07.28 |
코드로 안드로이드 방향 설정 (0) | 2010.07.24 |
OnTouch, Action_up (1) | 2010.07.24 |
Comment 0