其他分享
首页 > 其他分享> > android-单击登录按钮时以及从Web服务器获得验证时创建进度条

android-单击登录按钮时以及从Web服务器获得验证时创建进度条

作者:互联网

当我单击登录按钮时,进度条应该显示,而后端进程结束时,进度条却消失并移至其他活动,该怎么办
???硬件做到这一点?

请提供一段代码

解决方法:

您可以使用AsyncTask和ProgressDialog进行此操作

私人ProgressDialog进度;

    progress= new ProgressDialog(this);
    progress.setIndeterminate(true);
    progress.setMessage("I am thinking");

private class MyAsynch extends AsyncTask<String, Void, String>{
    protected void onPreExecute() {
        progress.show();
    }
    @Override
    protected String doInBackground(String...strings) { // <== DO NOT TOUCH THE UI VIEW HERE
        // TODO Auto-generated method stub
        String key= strings[0];
        String inString= strings[1];
        return encrypt(key, inString); // <== return value String result is sent to onPostExecute
    }
    protected void onPostExecute(String result){
        progress.dismiss();
        editTextConfusedText.setText(result); // you could launch results dialog here
    }
};

protected void onPause() {
    super.onPause();
    if (asynch != null) {asynch.cancel(true);}
    if (progress != null){progress.cancel();}
}

标签:progress-bar,web-services,android
来源: https://codeday.me/bug/20191208/2091953.html