如何显示一个AlertDialog生成器内的进度条带不带XML等元素一起? [英] How to show a Progress Bar inside an AlertDialog Builder along with other elements without an XML?

查看:268
本文介绍了如何显示一个AlertDialog生成器内的进度条带不带XML等元素一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了蓝牙传输创建AlertDialog转移通报Android手机感动了。

I am trying to create an AlertDialog for a Bluetooth transfer after the transfer notification is touched in an android phone.

我想是这样的:
出了下面的,我得到的一切 - 图标,标题和两个按钮。我相信,我可以添加其他信息一样从,文件名和使用的帮助AlertDialog.Builder性质光标等。我只是不知道它得到一个进度条。我不想使用XML。

I am trying something like this: Out of the below, I am getting everything - icon, title and two buttons. I am sure I can add other info like From, FileName and others using cursors with the help AlertDialog.Builder properties. I just do not know to get a progress-bar in it. I do not want to use an XML.

protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setIcon(R.id.imageFile);
    alertDialogBuilder.setTitle("File Transfer");

    ProgressDialog progressDialog;
    Context mContext = null;
    progressDialog = new ProgressDialog(mContext);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    //alertDialogBuilder.setView(progressDialog); //STUCK HERE
    //"!" icon and "File Transfer"
    //from : device name
    //File: <name>
    //Type: <type> (<size>)
    //Receiving/Sending File
    //<%> | Green progress bar
    //Hide and Stop buttons

    alertDialogBuilder.setPositiveButton("STOP", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    alertDialogBuilder.setNegativeButton("HIDE", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    return alertDialog;

}

我已经一切就绪,除了我无法弄清楚如何在这里带来了进度条。

I have everything in place except I am not able to figure out how to bring a progress-bar here.

可以用XML的布局我getjust一个进度条和

Can I getjust a progress-bar using XML layout and use as

alertDialogBu​​ilder.setView(R.id.what前所未有的XML文件)
或如何创建该进度条在他的Java文件本身并投入进度在该视图,然后把里面的对话这一观点的景色。

alertDialogBuilder.setView(R.id.what-ever-xml-file) Or how to create a view for that progress-bar in he Java file itself and put a progressbar in that view and then put that view inside the dialog.

我想某事像这样:

推荐答案

您可以使用对话框并在此通过添加进度

You can use Dialog and add ProgressBar on this by using

_dialog.addContentView(视图,则params)方法。

这篇关于如何显示一个AlertDialog生成器内的进度条带不带XML等元素一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆