Android中showDialog(int id)開發小記

來源:互聯網
上載者:User

在閱讀源碼是看到了這樣的寫法

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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.