单击按钮时如何显示进度条?

时间:2015-03-18 12:00:40

标签: java android onclicklistener android-progressbar

有人可以帮我设一个进度条,看起来与此类似; Example of Progress Bar

这是我的代码;

public class exampleAlert extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inf = getActivity().getLayoutInflater();
    final View theDIalog = inf.inflate(R.layout.example_xml, null);
    builder.setView(theDIalog);
    builder.setCancelable(true);

    final AlertDialog dialogscreen = builder.create();

    theDIalog.findViewById(R.id.Ok).setOnClickListener(new View.OnClickListener() { 

    @Override
        public void onClick(View v) {

            final ProgressDialog dialog = new ProgressDialog(getActivity());
            dialog.setTitle("Loading...");
            dialog.setMessage("Please wait.");
            dialog.setIndeterminate(true);
            dialog.setCancelable(false);
            dialog.show();

            long delayInMillis = 2500;
            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    dialog.dismiss();
                }
            }, delayInMillis);



        AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
        builder1.setMessage("Write your message here.");
        builder1.setCancelable(true);
        builder1.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
        //put your code that needed to be executed when okay is clicked
        dialogscreen.dismiss();


        }
        });

        AlertDialog alert11 = builder1.create();
        alert11.show();

        }

        });

        return dialogscreen;

}



 }

正如您所看到的,当单击“确定”按钮时,我将引入一个警告对话框。我想在此对话框出现在屏幕上之前带上进度条。

所以请有人帮我这样做。

如果您需要更多详细信息,请对此帖发表评论

0 个答案:

没有答案