显示进度对话框将数据存储到服务器

Show Progress Dialog Storing Data to Server

我允许用户创建一个帐户,然后sending/storing将数据发送到服务器

我想在用户点击注册按钮时显示进度对话框

这是我用来将数据插入数据库的代码

private void insertUser(){

    ...

    //Creating an anonymous callback
    new Callback<Response>() {
    @Override
    public void success(Response result, Response response) {
       .......

      //On success we will read the server's output using bufferedreader
      //Displaying the output as a toast
      Toast.makeText(MainActivity.this, output, Toast.LENGTH_LONG).show();
       }
    );
}

执行按钮点击的代码:

//Overriding onclick method
    @Override
    public void onClick(View v) {
        //Calling insertUser on button click
        insertUser();
    }

在 class 级别声明 ProgressDialog 对话框。

ProgressDialog dialog = new ProgressDialog(context);
dialog.setMessage("Some message");

现在在 insertUser() {} 中执行 dialog.show(); 现在里面

public void success(Response result, Response response){
    dialog.dismiss();
}