Android 从单独的线程类获取数据时,未显示进度对话框

Android 从单独的线程类获取数据时,未显示进度对话框,android,json,Android,Json,我使用单独的线程从url获取json对象。但问题是我想在得到结果的同时显示进度对话框。我已经创建了一个进度对话框,并在线程执行之前和之后调用了show和disclose。但未显示“进度”对话框。 这是我调用线程的方式 private void getRecordsByCount(final String data) { try { // btnSelectall.setText(" "); int color=Color.B

我使用单独的线程从url获取json对象。但问题是我想在得到结果的同时显示进度对话框。我已经创建了一个进度对话框,并在线程执行之前和之后调用了show和disclose。但未显示“进度”对话框。 这是我调用线程的方式

    private void getRecordsByCount(final String data) {
        try {
            // btnSelectall.setText(" ");
            int color=Color.BLACK;
            showProgressDialog();
            tableLayoutGrid.removeAllViews();
            final String[] details = data.split("_");
            SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
            String formattedDate = df.format(new Date());
            String url = ipaddress + "/GrantLeavesList?Companyid=" + user_info.get("CompanyId") + "&divisionid=" + details[3] + "&userid=" + user_info.get("userid") + "&roleid="
                    + user_info.get("RoleId") + "&Employeeid=" + user_info.get("EmployeeId") + "&leavetypeid=" + staticDetails.get(details[0]) + "&strStatus=" + staticDetails.get(details[1])
                    + "&type=" + staticDetails.get(details[2]) + "&Date=" + formattedDate;
            JsonThread thread = new JsonThread(url);
            thread.start();
            // thread.setPriority(Thread.MAX_PRIORITY);
            thread.join();
            JSONObject obj = thread.returnResult();
            btnGrantSubmit.setVisibility(View.GONE);
            if (obj != null) {

                leaveforwardcounts = obj.getJSONArray("Table1");

                ScrollView scrollGrid = new ScrollView(this);
                TableRow datarow = new TableRow(this);
                datarow.setWeightSum(100);
                TableLayout table = new TableLayout(this);
                for (int i = 0; i < leaveforwardcounts.length(); i++) {
                    btnGrantSubmit.setVisibility(View.VISIBLE);
                    JSONObject record = leaveforwardcounts.getJSONObject(i);
                    String applicantname = record.getString("Applicant");
                    String toDate = record.getString("ToDate");
                    String noofdays = record.getString("NumberOfDays");
                    String LOP = record.getString("LOP");
                    if(LOP!=null && LOP.trim().length()!=0)
                    {
                        color=Color.RED;
                    }
                    final int id = i;
                    final Button gridbutton = new Button(this);
                    gridbutton.setText(status);
                    gridbutton.setTextColor(Color.BLACK);
                    gridbutton.setBackgroundResource(R.drawable.grdbutton_30x30);
                    gridbutton.setGravity(Gravity.CENTER);
                    gridbutton.setPadding(2, 0, 2, 0);
                    gridbutton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            changeRadioButtonState(gridbutton, id, data);
                        }
                    });
                    gridbutton.setOnLongClickListener(new OnLongClickListener() {

                        @Override
                        public boolean onLongClick(View v) {
                            setSelection(gridbutton);
                            return true;
                        }
                    });

                    TextView tvApplicantName = new TextView(this);

                    TextView tvToDate = new TextView(this);
                    TextView tvNoOfDays = new TextView(this);
                    TextView empty = new TextView(this);
                    TextView empty2 = new TextView(this);
                    if (applicantname.trim().length() >= 18) {
                        applicantname = applicantname.substring(0, 18);
                    }

                    tvApplicantName.setText(applicantname);
                    tvApplicantName.setTypeface(font2);
                    tvApplicantName.setWidth(70);
                    tvApplicantName.setTextColor(color);
                    tvApplicantName.setPadding(5, 0, 0, 0);

                    tvToDate.setText(toDate);
                    tvToDate.setTypeface(font2);
                    tvNoOfDays.setText(noofdays);
                    tvNoOfDays.setTypeface(font2);
                    tvNoOfDays.setGravity(Gravity.RIGHT);

                    Button ivDetails = new Button(this);
                    ivDetails.setText(" ");
                    ivDetails.setPadding(2, 0, 2, 0);
                    ivDetails.setBackgroundResource(R.drawable.detailsbutton_30x30);
                    ivDetails.setGravity(Gravity.CENTER);

                    ivDetails.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            leaveDetails = new PopupWindow(showLeaveDetails(id, leaveforwardcounts,data), (int) (width * 0.8), height / 2, true);
                            leaveDetails.showAtLocation(mainlayout, Gravity.CENTER, 0, 0);
                        }
                    });

                    TableRow row = new TableRow(this);

                    row.setPadding(0, 3, 0, 3);
                    row.setWeightSum(100);
                    row.addView(tvApplicantName, new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 55));
                    row.addView(tvNoOfDays, new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 5));
                    row.addView(empty2, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 20));
                    row.addView(ivDetails, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 5));
                    row.addView(empty, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 5));
                    row.addView(gridbutton, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 5));
                    table.addView(row);
                }
                scrollGrid.addView(table);
                datarow.addView(scrollGrid, new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 100));
                tableLayoutGrid.addView(datarow);
                dialog.dismiss();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



package com.MobJax.dashboard;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.http.util.ByteArrayBuffer;
import org.json.JSONObject;


public class JsonThread extends Thread{
    boolean running=false;
    String url;
    JSONObject jobj=null;

    public JsonThread(String url)
    {
        this.url=url;
    }
    @Override
    public void run() {
        int k=0;

        URL url1;
        try {

            url1 = new URL(url);
            InputStream input=url1.openStream();
            BufferedInputStream bis=new BufferedInputStream(input);
            ByteArrayBuffer baf=new ByteArrayBuffer(1000);
            while((k=bis.read())!=-1)
            {
            baf.append((byte)k);

            }
            String results=new String(baf.toByteArray());
              jobj=new JSONObject(results);
            } 
        catch (MalformedURLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } 
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

    }
    public JSONObject returnResult()
    {
        return jobj;
    }

}
private void getRecordsByCount(最终字符串数据){
试一试{
//btselectall.setText(“”);
int color=color.BLACK;
showProgressDialog();
tableLayoutGrid.removeAllViews();
最终字符串[]详细信息=data.split(“”);
SimpleDataFormat df=新的SimpleDataFormat(“MM/dd/yyyy”);
字符串formattedDate=df.format(new Date());
字符串url=ipaddress+“/GrantLeavesList?Companyid=“+user\u info.get(“Companyid”)+”&divisionid=“+details[3]+”&userid=“+user\u info.get(“userid”)+”&roleid=”
+user_info.get(“RoleId”)+”和Employeeid=“+user_info.get(“Employeeid”)+”和leavetypeid=“+staticDetails.get(details[0])+”&strStatus=“+staticDetails.get(details[1]”)
+“&type=“+staticDetails.get(详细信息[2])+”&Date=“+formattedDate;
JsonThread线程=新的JsonThread(url);
thread.start();
//线程设置优先级(线程最大优先级);
thread.join();
JSONObject obj=thread.returnResult();
btnGrantSubmit.setVisibility(View.GONE);
如果(obj!=null){
leaveforwardcounts=对象getJSONArray(“表1”);
ScrollView scrollGrid=新的ScrollView(此);
TableRow datarow=新的TableRow(此);
datarow.setWeightSum(100);
TableLayout table=新的TableLayout(本);
对于(int i=0;i=18){
applicationName=applicationName.substring(0,18);
}
tvapplicationname.setText(applicationname);
TvAppliantName.setTypeface(font2);
TvAppliantName.setWidth(70);
TvAppliantName.setTextColor(颜色);
设置填充(5,0,0,0);
tvToDate.setText(toDate);
设置字体(font2);
tvNoOfDays.setText(noofdays);
设置字体(字体2);
tvNoOfDays.setGravity(Gravity.RIGHT);
按钮IV详细信息=新按钮(此按钮);
ivDetails.setText(“”);
设置填充(2,0,2,0);
ivDetails.setBackgroundResource(R.drawable.detailsbutton_30x30);
iv.设置重力(重力中心);
ivDetails.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
leaveDetails=新的弹出窗口(showLeaveDetails(id、leaveforwardcounts、data),(int)(宽度*0.8),高度/2,true);
leaveDetails.showAtLocation(主布局,重心,0,0);
}
});
TableRow row=新的TableRow(本);
设置填充(0,3,0,3);
行。设置权重总和(100);
row.addView(tvapplicationname,新表row.LayoutParams(LayoutParams.MATCH_父级,LayoutParams.WRAP_内容,55));
row.addView(tvNoOfDays,新表row.LayoutParams(LayoutParams.MATCH_父级,LayoutParams.WRAP_内容,5));
addView(empty2,新表row.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,20));
addView(ivDetails,newtableRow.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,5));
row.addView(空,新表row.LayoutParams(LayoutPa
public class MyTask extends AsyncTask<String, Void, String> {

private Context context;
private ProgressDialog progressDialog;

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

@Override
protected void onPreExecute() {
        progressDialog = ProgressDialog.show(context, "", "Loading...", true);
}

/* 
 * @see android.os.AsyncTask#doInBackground(Params[])
 */
@Override
protected String doInBackground(String... arg0) {
    //your json thread part
}

@Override
protected void onPostExecute(final String result) {
        progressDialog.dismiss();
}
}