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類中的方法
}
});

文檔中如是解釋

void android.app. Activity.showDialog(int id)

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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM