2016-11-07 9 views
0

progressbar.show()は効果がありません。ただし、私がshowPopUpを呼び出すと、奇妙な動作に気付きました()メソッドを2回実行すると、進行状況ダイアログが表示されますが、dismiss()を実行できません。ProgressDialog.show()は進行状況ダイアログを表示していません

package com.snapbizz.snapdashboard.Tabs.v1; 

import android.app.ProgressDialog; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.FrameLayout; 
import android.widget.LinearLayout; 
import android.widget.TextView; 

import com.snapbizz.snapdashboard.Core.v1.SalesData; 
import com.snapbizz.snapdashboard.R; 

import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.Date; 
import java.util.List; 


public class DashBoardSalesTab extends Fragment { 

    LinearLayout salesListContainer, salesBarConatainer; 
    LayoutInflater layoutInflater; 
    SalesData salesData; 
    ProgressDialog progressDialog; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.sales_page_layout, container, false); 
     return rootView; 
    } 

    public void showPopUp() { 
     progressDialog = new ProgressDialog(getContext(), ProgressDialog.THEME_HOLO_LIGHT); 
     progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
     progressDialog.setMessage("loading the page..."); 
     progressDialog.setProgressNumberFormat(null); 
     progressDialog.setProgressPercentFormat(null); 
     progressDialog.setIndeterminate(true); 
     progressDialog.show(); 

    } 

    public void synchronizeScrollers() { 
     getActivity().findViewById(R.id.page_scroller).setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       getActivity().findViewById(R.id.table_scroller).getParent() 
         .requestDisallowInterceptTouchEvent(true); 
       return false; 
      } 
     }); 
     getActivity().findViewById(R.id.table_scroller).setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       v.getParent().requestDisallowInterceptTouchEvent(true); 
       return false; 
      } 
     }); 
    } 

    public void renderSalesGraph(List<String[]> values, Float totalSumY) throws Exception { 

     salesBarConatainer.removeAllViews(); 
     for (String[] value : values) { 
      View barView = layoutInflater.inflate(R.layout.bar_char_item_layout, salesBarConatainer, false); 
      float sumOfSalesForTheDay = Float.parseFloat((value[0] == null) ? "0" : value[0]); 
      float weightofBar = sumOfSalesForTheDay/totalSumY; 
      barView.findViewById(R.id.bar_y).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, weightofBar)); 

      ((TextView) barView.findViewById(R.id.value_y)).setText(
        (sumOfSalesForTheDay == 0.0f ? "" : 
          getActivity().getResources().getString(R.string.rupee_symbol) + sumOfSalesForTheDay + "") 
      ); 
      SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy/MM/dd"); 
      SimpleDateFormat outputFormat = new SimpleDateFormat("dd-MMM-yyyy"); 
      Date renderingDate = inputFormat.parse(value[2]); 
      String[] date = outputFormat.format(renderingDate).split("-"); 
      ((TextView) barView.findViewById(R.id.value_x_date)).setText(date[0] + " " + date[1]); 
      ((TextView) barView.findViewById(R.id.value_x_year)).setText(date[2]); 
      salesBarConatainer.addView(barView); 
     } 
    } 

    public void renderSalesGraphForMonths(List<String[]> values, Float totalSumY) throws Exception { 
     LinearLayout salesBarConatainer = (LinearLayout) getActivity().findViewById(R.id.bars_container); 
     salesBarConatainer.removeAllViews(); 
     for (String[] value : values) { 
      View barView = layoutInflater.inflate(R.layout.bar_char_item_layout, salesBarConatainer, false); 
      float sumOfSalesForTheDay = Float.parseFloat((value[0] == null) ? "0" : value[0]); 
      float weightofBar = sumOfSalesForTheDay/totalSumY; 
      barView.findViewById(R.id.bar_y).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, weightofBar)); 

      ((TextView) barView.findViewById(R.id.value_y)).setText(
        (sumOfSalesForTheDay == 0.0f ? "" : 
          getActivity().getResources().getString(R.string.rupee_symbol) + sumOfSalesForTheDay + "") 
      ); 
      SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy/MM"); 
      SimpleDateFormat outputFormat = new SimpleDateFormat("MMM-yyyy"); 
      Date renderingDate = inputFormat.parse(value[2]); 
      Calendar cal = Calendar.getInstance(); 
      cal.set(Calendar.MONTH, renderingDate.getMonth()); 
      cal.set(Calendar.DAY_OF_MONTH, 1); 

      barView.setOnClickListener(new MonthBarClickListener(cal)); 
      String[] date = outputFormat.format(renderingDate).split("-"); 
      ((TextView) barView.findViewById(R.id.value_x_date)).setText(date[0]); 
      ((TextView) barView.findViewById(R.id.value_x_year)).setText(date[1]); 
      salesBarConatainer.addView(barView); 
     } 
    } 

    public String[] addTOSalesTable(String date, boolean header) throws Exception { 
     List<String[]> values = salesData.getSalesTableData(date); 
     String[] value = values.get(0); 
     String[] newValue = {value[0], value[1], date}; 
     String totalSales = (value[0] == null) ? "0" : value[0]; 
     String totalCredit = (value[1] == null) ? "0" : value[1]; 
     String totalCash = (Float.parseFloat(totalSales) - Float.parseFloat(totalCredit)) + ""; 
     String rupeeSymbol = getActivity().getResources().getString(R.string.rupee_symbol); 
     if (!header) { 
      View salesRow = layoutInflater.inflate(R.layout.sales_page_table_row_layout, salesListContainer, false); 
      ((TextView) (salesRow.findViewById(R.id.sale_date))). 
        setText(date); 
      ((TextView) (salesRow.findViewById(R.id.sales_total_sale))). 
        setText(rupeeSymbol + " " + totalSales); 
      ((TextView) (salesRow.findViewById(R.id.sales_total_cash))). 
        setText(rupeeSymbol + " " + totalCash); 
      ((TextView) (salesRow.findViewById(R.id.sales_total_credit))). 
        setText(rupeeSymbol + " " + totalCredit); 
      ((TextView) (salesRow.findViewById(R.id.sales_ttoal_coupon))). 
        setText(rupeeSymbol + " " + "0"); 
      if (salesListContainer.getChildCount() % 2 != 0) { 
       salesRow.setBackgroundColor(getResources().getColor(R.color.table_row_alternate_color)); 
      } 
      salesListContainer.addView(salesRow); 
     } else { 
      ((TextView) (getActivity().findViewById(R.id.sales_header_total_sales))). 
        setText(rupeeSymbol + " " + totalSales); 
      ((TextView) (getActivity().findViewById(R.id.sales_header_total_cash))). 
        setText(rupeeSymbol + " " + totalCash); 
      ((TextView) (getActivity().findViewById(R.id.sales_header_total_credit))). 
        setText(rupeeSymbol + " " + totalCredit); 
      ((TextView) (getActivity().findViewById(R.id.sales_header_total_coupon))). 
        setText(rupeeSymbol + " " + "0"); 
      DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); 
      Date presentDate = new Date(); 
      ((TextView) (getActivity().findViewById(R.id.sales_header_day))). 
        setText(date.contentEquals(dateFormat.format(presentDate)) ? "Today" : date); 
     } 
     return newValue; 
    } 

    public void getMonths() throws Exception { 
     Calendar cal = Calendar.getInstance(); 
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM"); 

     List<String[]> values = new ArrayList<>(); 
     float totalSumY = 0.0f; 
     for (int i = 0; i < 12; i++) { 
      cal.add(Calendar.MONTH, (i == 0) ? 0 : -1); 
      String date = dateFormat.format(cal.getTime()); 
      String[] value = salesData.getSalesDataForMonth(date); 
      String[] newValue = {value[0] == null ? "0" : value[0], value[1] == null ? "0" : value[1], date}; 
      totalSumY += Float.parseFloat(value[0] == null ? "0" : value[0]); 
      values.add(newValue); 
     } 
     renderSalesGraphForMonths(values, totalSumY); 
    } 

    public void initChart() { 
     FrameLayout dayButton = (FrameLayout) getActivity().findViewById(R.id.day_button); 
     FrameLayout monthButton = (FrameLayout) getActivity().findViewById(R.id.month_button); 
     dayButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       try { 
        ((TextView) getActivity().findViewById(R.id.button_day_text)).setTextColor(
          getResources().getColor(R.color.dark_darkblue) 
        ); 
        ((TextView) getActivity().findViewById(R.id.button_day_text)). 
          setBackground(getResources().getDrawable(R.drawable.button_border_active)); 

        ((TextView) getActivity().findViewById(R.id.button_month_text)).setTextColor(
          getResources().getColor(R.color.default_text_color) 
        ); 
        ((TextView) getActivity().findViewById(R.id.button_month_text)). 
          setBackground(getResources().getDrawable(R.drawable.button_border)); 

        generateTablesRows(Calendar.getInstance(), 60, -1); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
      } 
     }); 
     monthButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       try { 
        ((TextView) getActivity().findViewById(R.id.button_month_text)).setTextColor(
          getResources().getColor(R.color.dark_darkblue) 
        ); 
        ((TextView) getActivity().findViewById(R.id.button_month_text)). 
          setBackground(getResources().getDrawable(R.drawable.button_border_active)); 

        ((TextView) getActivity().findViewById(R.id.button_day_text)).setTextColor(
          getResources().getColor(R.color.default_text_color) 
        ); 
        ((TextView) getActivity().findViewById(R.id.button_day_text)). 
          setBackground(getResources().getDrawable(R.drawable.button_border)); 
        getMonths(); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 

      } 
     }); 
    } 

    public void generateTablesRows(Calendar cal, int limit, int increment) throws Exception { 
     salesListContainer.removeAllViews(); 
     float totalSumY = 0.0f; 
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); 
     List<String[]> barGraphValues = new ArrayList<>(); 
     for (int i = 0; i < limit; i++) { 
      cal.add(Calendar.DATE, (i == 0) ? 0 : increment); 
      String date = dateFormat.format(cal.getTime()); 
      String[] value = addTOSalesTable(date, (i == 0) ? true : false); 
      totalSumY += Float.parseFloat((value[0] == null) ? "1" : value[0]); 
      barGraphValues.add(value); 
     } 
     renderSalesGraph(barGraphValues, totalSumY); 
    } 

    @Override 
    public void onActivityCreated(@Nullable Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
     showPopUp(); 
     layoutInflater = LayoutInflater.from(getContext()); 
     salesListContainer = (LinearLayout) (getActivity().findViewById(R.id.sales_list_container)); 
     salesListContainer.removeAllViews(); 
     salesBarConatainer = (LinearLayout) getActivity().findViewById(R.id.bars_container); 
     salesBarConatainer.removeAllViews(); 
     new SalesTabLoader().execute(); 

    } 

    public class MonthBarClickListener implements View.OnClickListener { 
     Calendar cal; 

     public MonthBarClickListener(Calendar cal) { 
      this.cal = cal; 
     } 

     @Override 
     public void onClick(View v) { 
      try { 
       //new SalesAsyncTask(cal).execute(cal.getActualMaximum(Calendar.DAY_OF_MONTH),1); 
       generateTablesRows(cal, cal.getActualMaximum(Calendar.DAY_OF_MONTH), 1); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public class SalesTabLoader extends AsyncTask<Void, Void, Void> { 
     @Override 
     protected Void doInBackground(Void... params) { 
      salesData = new SalesData(getContext()); 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void aVoid) { 
      super.onPostExecute(aVoid); 
      try { 
       initChart(); 
       generateTablesRows(Calendar.getInstance(), 60, -1); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } finally { 
       synchronizeScrollers(); 
       progressDialog.dismiss(); 
      } 
     } 
    } 

} 
+1

それはあなたのために働いていたことが受け入れられて答えをマークしてください –

答えて

2

このようにしてみてください。

progressDialog = new ProgressDialog(getActivity()); 

そして、あなたはあなたのダイアログをカスタマイズし、自己を入れたい場合は、それにレイアウトを作成しました。

/** 
* Created by vivek on 18/10/16. 
*/ 
public class CustomDialog { 
    private static Dialog dialog; 
    private static Context context; 

    public CustomDialog(Context context) { 
     this.context = context; 
    } 

    /** 
    * Comman progress dialog ... initiates with this 
    * 
    * @param message 
    * @param title 
    */ 
    public static void showProgressDialog(Context context, String title, String message) { 
     if (dialog == null) 
     { 
      dialog = new Dialog(context); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(R.layout.custom_loader); 
      dialog.setCancelable(false); 
      dialog.setCanceledOnTouchOutside(false); 
      dialog.show(); 
     } 
    } 

    public static boolean isProgressDialogRunning() { 
     if (dialog != null && dialog.isShowing()) { 
      return true; 
     } else return false; 
    } 

    /** 
    * Dismiss comman progress dialog 
    */ 
    public static void dismissProgressDialog() { 
     if (dialog != null && dialog.isShowing()) { 
      dialog.dismiss(); 
      dialog = null; 
     } 
    } 
} // End of main class over here ... 
+0

progressdialogビルダーで)(getActivityを試してみてください:)両方試しました – AndroidHacker

+0

、これがなかった場合は進行が:( –

+0

をアップダイアログを取得する:(他の方法では動作しませんでした – AndroidHacker

0

があります。あなたは2つのprogressdialogとその両方のprogressbarを画面に表示していますが、そのときにprogressbarを却下すると、前のものが他のものに優先されてから最初のものが解除されます。それが問題です。

+0

興味深い考えですが、showPopup()メソッドを一度呼び出すとプログレスダイアログがポップアップしないので、showPopup()を呼び出すとポップアップが表示されます)2回。あなたはそれについて何を言いたいですか? –

+0

showPopup()を2回呼び出して前のプログレスバーをメモリにも画面上にも呼び出すと@abhishekramkrishnaが参照されますが、その参照はshowPopup()あなたの画面やアクティビティには2つのプログレスバーが1番目と2番目にあり、今度は2番目のプログレスバーのリファレンスが変数にあります最初のものではありません。プログレスバーを却下すると、2番目のものだけが却下されます。 1番目のプログレスバーは、1番目のプログレスバーの変数に参照がないため、アクティビティが終了するまで常に画面に表示されます。とった?? –

1

これを交換: -

progressDialog = new ProgressDialog(getActivity()); 
+0

did not works :(他の方法では? –

+0

あなたのコードに問題があります。あなたのshowPopup()メソッドが正しいかどうかチェックしました。 –

0

progressDialog = new ProgressDialog(getContext(), ProgressDialog.THEME_HOLO_LIGHT); 

を私は答えのeverything.Butのいずれもissue.Howeverを解決していない、私は断片にonResume()メソッドをオーバーライドすることによってそれを解決しようとしました。

ありがとうございます。

関連する問題