https://soo0100.tistory.com/1900
기본 다이얼로그 박스 만들기
안드로이드 Alert Dialog 라고 불리는 기본 다이얼로그를 만들어 봅니다. 결과는 하기와 같습니다. 1. XML 화면구성으로 버튼을 하나 만듭니다. 해당 버튼을 누르면 다이얼로그가 나오게 구현하기
soo0100.tistory.com
Alert 기본 다이얼로그 에서 하기 처럼 리스트형을 만들어 봅니다.
지난 시간과 XML 및 코드 구성은 동일합니다.
다만, 해당 리스트 형식을 위해서 신규 함수를 만들어 버튼뷰의 Onclick 이벤트에 적용시킵니다.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="AlertDialogListType"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="AlertDialogListType"
android:text="Alert Dialog"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2. MainActivity 에 onClick 호출시 불려지는 함수를 추가합니다.
해당 함수 내에서 리스트형 alert Dialog 를 구현 해 봅니다.
final CharSequence[] items ={"제주", "프랑크푸르트" , "파리"};
//list 타입의 다이얼로 박스
public void AlertDialogListType(View view){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("목적지를 선택하세요");
builder.setItems(items, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int num) {
Toast.makeText(getApplicationContext(), items[num], Toast.LENGTH_LONG).show();
}
});
builder.show();
}
builder.setItems() 함수를 사용해서, 리스트 메뉴를 만드는 동시에 익명클래스를 활용해서 클릭 리스너를 통합적으로 구현 해줍니다.
위에서는 각 리스트 별로, 간단한 토스트 메시지만 띄웠지만 상황에 맞게 구현을 하면 되겠습니다.
감사합니다.
대화상자 | Android 개발자 | Android Developers
대화상자 대화상자는 사용자에게 결정을 내리거나 추가 정보를 입력하라는 메시지를 표시하는 작은 창입니다. 대화상자는 화면을 가득 채우지 않으며 보통은 사용자가 다음으로 계속 진행하기
developer.android.com
https://soo0100.tistory.com/1902
체크박스 형 기본 다이얼로그 만들기
https://soo0100.tistory.com/1901 리스트형 기본 다이얼로그 만들기 https://soo0100.tistory.com/1900 기본 다이얼로그 박스 만들기 안드로이드 Alert Dialog 라고 불리는 기본 다이얼로그를 만들어 봅니다. 결..
soo0100.tistory.com
'앱 만들기 > 안드로이드 study' 카테고리의 다른 글
체크박스 형 기본 다이얼로그 만들기 (8) | 2022.07.19 |
---|---|
기본 다이얼로그 박스 만들기 (8) | 2022.07.18 |
팝업 메뉴 만들기 (6) | 2022.07.15 |
플로팅 컨텍스트 메뉴 만들기 (4) | 2022.07.14 |
옵션 메뉴 만들기 (6) | 2022.07.12 |
댓글