Android中showDialog(int id)开发小记
在阅读源码是看到了这样的写法
LinearLayout addAudioBtn = (LinearLayout) findViewById(R.id.create_audio_list_header);
addAudioBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(1);//直接是系统Activity类中的方法
}
});
文档中如是解释
Simple version of showDialog(int,
Bundle)
that does not take any arguments. Simply calls showDialog(int,
Bundle)
with null arguments.
- Parameters:
- id
我之前开发都是这样调用
private void showDownloadDialog() {
downloadDialog = new ProgressDialog(this);
downloadDialog.setMessage(getString(R.string.alert_download_msg));
downloadDialog.setCancelable(false);
downloadDialog.show();
}
仔细看了一下,原来是与下面这个方法一起使用的
@Override
protected Dialog onCreateDialog(int id) {
final SystemService systemService = new SystemService(this);
Set<String> folderList = systemService.getFolderContainMedia();
choices = folderList.toArray(new String[folderList.size()]);
// 选项数组
// String[] choices = { "Facebook", "Twitter" };
// Check判断数组,与选项对应
// boolean[] chsBool = { true, false };
AlertDialog dialog = CommonAlertDialogBuilder.getInstance(this)
.setIcon(R.drawable.ic_menu_scan).setTitle("请选择")
.setMultiChoiceItems(choices, null,
new OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which, boolean isChecked) {
if (isChecked) {
checkedItem.add(which);
} else {
checkedItem.remove((Object) which);
}
}
}).setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// System.out.println(checkedItem.toString());
for (int i = 0; i < checkedItem.size(); i++) {
// System.out.println(choices[checkedItem
// .get(i)]);
addMediaToPlaylist(systemService
.getMediasByFolder(choices[checkedItem
.get(i)]));
System.out
.println(systemService
.getMediasByFolder(
choices[checkedItem
.get(i)])
.toString());
}
showProcessDialog();
mRunnable.run();
checkedItem.clear();
}
}).setNegativeButton("No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
checkedItem.clear();
}
}).create();
return dialog;
}