本文介绍了ProgressDialog在加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到我的Andr​​oid应用程序有问题。我创建一个货币转换器​​。我需要创建当你从一种货币转换值到另一个时出现的progressdialog。

I am encountering a problem in my Android application. I am creating a currency converter. I need to create a progressdialog that appears when you convert a value from one currency to another.

下面是我的code的一部分:

Here is part of my code:

        if (text1.equals("US Dollar - USD") && text2.equals("Euro - EUR") && edittextdollars.length() > 0 && edittexteuros.length()==0) {
            dialog1 = ProgressDialog.show(getActivity(), "", "Calculating...");
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try{
                    convertvalues("USD", "EUR");
                    handler.sendEmptyMessage(0);
                    }
                    catch (Exception e) {
                        edittexteuros.setText("Error");
                    }

                }
            });
            thread.start();
        }
private Handler handler = new Handler () {
    public void handleMessage(android.os.Message msg) {
        switch (msg.what) {
        case 0:
        dialog1.dismiss();
        break;
        }
    }
};

该progressdialog来了又走了,但没有任何反应的背景。这里是什么我的应用程序看起来像一些图片:

The progressdialog comes up and goes away, but nothing happens in the background. Here are a few pics of what my app looks like:

这是progressdialog到来之前。

This is before the progressdialog comes.

当我preSS计算:

在progressdialog完成后:

After the progressdialog finishes:

正如你所看到的,progressdialog消失后,我的价值观不进行转换。

As you can see, after the progressdialog goes away, my values don't convert.

在我的code,

convertvalues("USD", "EUR");

刚刚从互联网上获得的实际币值,并与我的EditText值相乘。没有什么不妥之处,它的工​​作没有progressdialog。我已经很多次测试它自己。

just gets actual currency value from the internet and multiplies it with the value in my edittext. There is nothing wrong with it and it worked without the progressdialog. I have tested it many times myself.

我在做什么错在这里?我已经检查了谷歌一个多星期,但我无法找到一个单一的解决方案。关于这个问题的任何帮助是极大的AP preciated。

What am I doing wrong here? I have checked Google for over a week, but I could not find a single solution. Any help regarding this problem is greatly appreciated.

推荐答案

您可以在Android中使用的AsyncTask

you can use asynctask in android

见下code可能是它会帮助你。

see following code may be it will help you..

private class asyncTask extends AsyncTask<Void, Void, Boolean> 
    {
        Context context;
        ProgressDialog pd;

        asyncTask(Context context)
        {
            this.context = context; 
            pd = new ProgressDialog(activityContext);

        } 
        protected void onPreExecute() 
        {
            pd.setTitle("Loading..");
            pd.setMessage("Please wait ...");
            pd.setCancelable(false);
            pd.show();
        } 
        protected void onPostExecute(Boolean result)
        {
            if(pd.isShowing()) pd.dismiss();
        } 

        @Override
        protected Boolean doInBackground(Void... params) 
        {
            convertvalues();

            return boolean_value;
        }
}

并调用该AsyncTask的以

And Just Call this asynctask with

new asyncTask(Your_Context).execute();

这篇关于ProgressDialog在加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 08:10