Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
进度对话框Android_Android_Progressdialog - Fatal编程技术网

进度对话框Android

进度对话框Android,android,progressdialog,Android,Progressdialog,我是android新手。现在我在ArrayAdapter中使用AsyncTask。当我使用ProgressDialog时,它显示以下错误 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application 04-25 08:07:40.881: E/AndroidRuntime(6417): at android.view.Vi

我是android新手。现在我在ArrayAdapter中使用AsyncTask。当我使用ProgressDialog时,它显示以下错误

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
        04-25 08:07:40.881: E/AndroidRuntime(6417):     at android.view.ViewRootImpl.setView(ViewRootImpl.java:563)
        04-25 08:07:40.881: E/AndroidRuntime(6417):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:269)
下面是我的代码

public class ExpandableListAdapter1 extends BaseExpandableListAdapter {

    private Context _context;
    private List<String> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<String, List<String>> _listDataChild;


    CommonFunctions cfObj;
    public ExpandableListAdapter1(Context context, List<String> listDataHeader,
            HashMap<String, List<String>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }

    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(final int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_seconditem, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.lblListItem);

        Button mtAccept=(Button)convertView.findViewById(R.id.btnAccept);
        Button mtReject=(Button)convertView.findViewById(R.id.btnReject);

        mtAccept.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                System.out.println("Accept clickable");
                System.out.println("Group number"+groupPosition);
                System.out.println("child number"+childPosition);

                //_context.startService(new Intent(_context, GroupResponds.class));
                new Worker().execute();

            }
        });

        mtReject.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                System.out.println("Reject clickable");
            }
        });

        txtListChild.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);

        ImageView img_selection=(ImageView) convertView.findViewById(R.id.imageside);
        int imageResourceId = isExpanded ? R.drawable.btn_up
                : R.drawable.btn_down;
        img_selection.setImageResource(imageResourceId);
        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    private class Worker extends AsyncTask<Integer, String, Integer>
    {
        ProgressDialog dialog;
        boolean device_error=false;
        String temp_encrypted_device_id=null;
        String result=null;
        String device_id="";


        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            cfObj=new CommonFunctions(_context);
            dialog=new ProgressDialog(_context);

            System.out.println("first....");

            dialog.setOnCancelListener(new DialogInterface.OnCancelListener(){
                public void onCancel(DialogInterface dialog) 
                {
                    Worker.this.cancel(true);
                }
            });
            System.out.println("second....");
            dialog.setMessage(_context.getResources().getString(R.string.initilalising));
            System.out.println("third....");
            if(dialog==null){
                System.out.println("dialog null....");
            }else{
            dialog.show();
            }
            System.out.println("fourth....");

        }
        @Override
        protected Integer doInBackground(Integer... params) {
            // TODO Auto-generated method stub
            device_id=cfObj.get_device_details();
            if(device_id==null||device_id=="")
            {
                device_error=true;
            }
            else
            {
                device_error=false;
            }
            if(device_error!=true)
            {
                publishProgress(_context.getString(R.string.internet_connectivity_checking));
            }

            return null;
        }
        @Override
        protected void onPostExecute(Integer result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            System.out.println("device id"+device_id);
            dialog.dismiss();
        }
        @Override
        protected void onProgressUpdate(String... values) {
            // TODO Auto-generated method stub
            super.onProgressUpdate(values);
            dialog.setMessage(values[0]);
        }


    }   

似乎您的成员变量_context是用于创建对话框的无效上下文。您需要将活动传递给适配器,而不是通过getApplicationContext获得的应用程序上下文。

Post full stack trace。