728x90
Single choice list
- public class AlertDialog extends Dialog
- /res/values/~.xml
-
- Dialog에서 보여줄 선택 목록을 정의 한다.
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string-array name="smartqrcode_language_array">
<item>UTF-8</item>
<item>Shift_JIS</item>
<item>ISO-8859-1</item>
</string-array>
</resources>
- Activity
private static final int DIALOG_SINGLE_CHOICE_CATEGORY = 0;
//--- Dialog를 화면에 표시 한다.
showDialog(DIALOG_SINGLE_CHOICE_CATEGORY); //--- Dialog 표시
//--- 화면에 표시할 Dialog를 작성 한다.
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = null;
AlertDialog alert = null;
switch (id) {
case DIALOG_SINGLE_CHOICE_CATEGORY:
builder = new AlertDialog.Builder(this);
//--- 아이콘 지정
builder.setIcon(R.drawable.smartqrcode_icon);
//--- 제목 지정
builder.setTitle(R.string.smartqrcode_category);
builder.setSingleChoiceItems(
//--- 선택 목록 지정
R.array.smartqrcode_category_array,
0, //--- 초기 선택 값 지정 (0, 1, 2, ...)
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int item) {
//--- item. 선택된 값의 index
String[] items = null;
String strItem = null;
items = getResources().getStringArray(
R.array.smartqrcode_category_array);
strItem = items[item]; //--- 선택된 항목
dialog.dismiss(); //--- Dialog 닫기
}
}
);
alert = builder.create();
break;
}
return alert;
}728x90
'Android' 카테고리의 다른 글
| 안드로이드 java string 줄바꿈 (0) | 2012.07.29 |
|---|---|
| 안드로이드 어플리케이션 스타일 (0) | 2012.07.29 |
| Android intent - Application 호출 (0) | 2012.07.29 |
| android : spinner 사용방법 (0) | 2012.07.29 |
| 안드로이드 dialog 사용방법 (0) | 2012.07.29 |