[ 코드에 들어가기 전에 ]
- 코드에서 중요하게 생각하는 부분과, 새로 공부하는 부분만 발췌해서 부연 설명
- 코드 전체를 첨부하기에는 비슷한 부분의 반복이고, 읽기도 힘들고, 길어지니 링크 참조
- https://miny-genie.tistory.com/57
<!-- XML Code_Toast -->
~~~~~~~~~~~~~~~~~~~~ ( 생략 ) ~~~~~~~~~~~~~~~~~~~~
<LinearLayout
~~~~~~~~~~~~~~~~~~~~ ( 생략 ) ~~~~~~~~~~~~~~~~~~~~
</LinearLayout>
<!-- XML Code_Dialog -->
~~~~~~~~~~~~~~~~~~~~ ( 생략 ) ~~~~~~~~~~~~~~~~~~~~
<LinearLayout
~~~~~~~~~~~~~~~~~~~~ ( 생략 ) ~~~~~~~~~~~~~~~~~~~~
</LinearLayout>
Dialog.xml
// JAVA Code
~~~~~~~~~~~~~~~~~~~~ ( 생략 ) ~~~~~~~~~~~~~~~~~~~~
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialogView = (View) View.inflate(MainActivity.this, R.layout.dialog, null);
AlertDialog.Builder dlg = new AlertDialog.Builder(MainActivity.this);
editID = (EditText) dialogView.findViewById(R.id.editID);
editPW = (EditText) dialogView.findViewById(R.id.editPW);
dlg.setView(dialogView);
editID.setText(txtID.getText());
editPW.setText(txtPW.getText());
dlg.setNegativeButton("확인", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int i) {
txtID.setText(editID.getText());
txtPW.setText(editPW.getText());
}
});
dlg.setPositiveButton("취소", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast toast = new Toast(MainActivity.this);
toastView = (View) View.inflate(MainActivity.this, R.layout.toast, null);
toastText = (TextView) toastView.findViewById(R.id.toastext);
toastText.setText("★ Cancel ★");
toast.setView(toastView);
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
Point point = new Point();
display.getSize(point);
int xOffset = (int) (Math.random() * point.x);
int yOffset = (int) (Math.random() * point.y);
// getWidth(), getHeight() is deprecated in android studio
toast.setGravity(Gravity.TOP | Gravity.LEFT, xOffset, yOffset);
toast.show();
}
});
dlg.show();
}
});
}
}
'학교 공부 > 안드로이드 프로그래밍' 카테고리의 다른 글
직접 풀어보기 8-2 (교재 P.349) (0) | 2022.05.03 |
---|---|
직접 풀어보기 8-1 (교재 P.335) (0) | 2022.05.03 |
직접 풀어보기 7-2 (교재 P.301) (0) | 2022.05.03 |
직접 풀어보기 7-1 (교재 P.295) (0) | 2022.05.03 |
직접 풀어보기 6-2 (교재 P.259) (1) | 2022.03.31 |