Android 如何在HTTP POST上显示进度条?

Android 如何在HTTP POST上显示进度条?,android,multithreading,http-post,handler,Android,Multithreading,Http Post,Handler,我正在尝试将视频上载到api,我想知道如何显示进度条,并在上载完成后关闭它 public class Loadvid extends AsyncTask <Object,Integer,String>{ EditText etxt_user = (EditText) findViewById(R.id.user_email); EditText etxt_pass = (EditText) findViewById(R.id.friend_email)

我正在尝试将视频上载到api,我想知道如何显示进度条,并在上载完成后关闭它

public class Loadvid extends AsyncTask <Object,Integer,String>{
        EditText etxt_user = (EditText) findViewById(R.id.user_email);
        EditText etxt_pass = (EditText) findViewById(R.id.friend_email);

        protected void onPreExecute(){
            dialog = new ProgressDialog(share.this);
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dialog.setMax(100);
            dialog.show();
            super.onPreExecute();

        }

        @Override
        protected String doInBackground(Object... params) {

            if(etxt_user.equals("")||etxt_pass.equals("")){
                dialog.dismiss();
                Alert.setMessage("Please fill in the Blanks");
                Alert.show();

            }
else{
        Pattern keys= Pattern.compile("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
                        "\\@" +
                        "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
                        "(" +
                        "\\." +
                        "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
                        ")+");
            Matcher matcher = keys.matcher((CharSequence) etxt_user);
            Matcher matcher1 = keys.matcher((CharSequence) etxt_pass);
            if(!matcher.matches()|| !matcher1.matches())
{
                    dialog.dismiss();
                    Alert.setMessage("Wrong email address.");
                    Alert.show();

                }
            }

            //implement the httppost.
        try
            {

 MultipartEntity me = new MultipartEntity();

 me.addPart("file", new FileBody(new File("/")));

 httppost.setEntity(me);

 HttpResponse responsePOST = client.execute(httppost);  
 HttpEntity resEntity = responsePOST.getEntity(); 

 InputStream inputstream = resEntity.getContent();
 BufferedReader buffered = new BufferedReader(new InputStreamReader(inputstream));
 StringBuilder stringbuilder = new StringBuilder();
 String currentline = null; 

 while ((currentline = buffered.readLine()) != null)
    { 
     stringbuilder.append(currentline + "\n"); 
     String result = stringbuilder.toString(); 
     Log.v("HTTP UPLOAD REQUEST",result); 
     inputstream.close();}  
}

     catch (Exception e) {
     e.printStackTrace();

    }


            return null;
        }


        protected void onPostExecute(String result){

            super.onPostExecute(result);

            if(result==null){
                dialog.dismiss();
                Alert.setMessage("The result failed");
                Alert.show();
                return;
            }
            else
            {

                Intent intent = new Intent("com...");
                startActivity(intent);
            }
        }


    }
@“在后台执行”

在我生命中的某个地方


我做错了什么,救命啊

只需使用它就可以了:在后台执行长时间运行的代码并正确更新UI(在UI线程上)。

谢谢Peter,我已经尝试过使用async task,但在上传时失败了。我会用我的新资料更新我的问题。
Matcher matcher = keys.matcher((CharSequence) etxt_user);