自定义进度对话框不显示

时间:2020-06-12 18:50:58

标签: java android android-asynctask progressdialog

我有一个自定义进度对话框,该对话框应该显示在我的asynctask中,但不幸的是没有。 该错误发生在我身上一次,但这是因为我在新线程中运行了onBackground方法。 但是现在我不这样做了,当我的onBackgroundMethod运行时没有任何显示,有帮助吗?

我的asyncTask:

 private class SyncData extends AsyncTask<String, String, String> {
        String msg;

        @Override
        protected void onPreExecute() //Starts the progress dailog
        {
            System.out.println("pre");
            customProgress = new CustomProgress();
            customProgress.showProgress(LoggedInAr.this,"Loading...",false);
           // progress = new CustomProgress();
           // progress.showProgress(LoggedInAr.this, "Loading..."
                   // ,false);
        }

        @Override
        protected String doInBackground(String... strings)  // Connect to the database, write query and add items to array list
        {
            runOnUiThread(new Runnable() {
                public void run() {


                    try {
                        Connection conn = connectionClass.CONN(); //Connection Object
                        if (conn == null) {
                            success = false;
                            msg = "Sorry something went wrong,Please check your internet connection";
                        } else {
                            // Change below query according to your own database.



                            Statement stmt = conn.createStatement();
                            ResultSet rs = stmt.executeQuery(query);


                            if (rs != null) // if resultset not null, I add items to itemArraylist using class created
                            {
                                while (rs.next()) {

                                    try {
                                        Bitmap imagebitmap;
                                        Blob rsBlob = rs.getBlob("ProductImage");
                                        itemArrayList.add(new ClassListItems(rs.getString("ProductArabicName"), rs.getString("ProductEnglishName"), rs.getString("ProductPrice"),rsBlob
                                        ,rs.getString("ProductID"),rs.getString("StoreArabicName")));
                                        System.out.println(rs.getString("ProductDescription"));

                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                }


                                success = true;
                            } else {

                                success = false;
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Writer writer = new StringWriter();
                        e.printStackTrace(new PrintWriter(writer));
                        msg = writer.toString();
                        Log.d("Error", writer.toString());
                        success = false;
                    }

                }
            });
            return msg;
        }


        @Override
        protected void onPostExecute(String msg) // disimissing progress dialoge, showing error and setting up my listview
        {
            System.out.println("post");

                customProgress.hideProgress();


           // progress.hideProgress();
            if (msg!=null){
                Toast.makeText(LoggedInAr.this, msg + "", Toast.LENGTH_LONG).show();
            }

            if (!success) {
            } else {
                try {
                    myAppAdapter = new MyAppAdapter(itemArrayList, LoggedInAr.this);
                    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
                    listView.setAdapter(myAppAdapter);
                } catch (Exception ex) {

                }

            }
        }
    }

0 个答案:

没有答案
相关问题