如何在这种情况下使用进度条?我想要一个进度条显示一旦点击注册按钮,如果注册成功,我也想给用户一个成功的按摩:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sme);
Firebase.setAndroidContext(this);
bizname = (EditText) findViewById(R.id.bizname);
location = (EditText) findViewById(R.id.location);
biztype = (EditText) findViewById(R.id.biztype);
pin = (EditText) findViewById(R.id.pin);
register = (Button) findViewById(R.id.register);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
register.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(View v) {
//Creating firebase object
**progressBar.setVisibility(View.VISIBLE);**
final Firebase ref = new Firebase("https://mcn-africa.firebaseio.com/");
//Getting values to store
String Username = bizname.getText().toString();
String Name = biztype.getText().toString();
String Id = pin.getText().toString();
String Location = location.getText().toString();
Members members = new Members();
members.setUsername(Username);
members.setLocation(Location);
members.setName(Name);
members.setId(Id);
Firebase newRef = ref.child("SMEs").push();
newRef.setValue(members);
progressBar.setVisibility(View.GONE);
}
});
}
} 任何想法将不胜感激
答案 0 :(得分:0)
您可以简单地使用绿色和红色条来显示登录是否成功。
答案 1 :(得分:0)
您无法在注册过程中显示进度。您唯一能做的就是在注册过程中提供进度加载器,或者在调用注册时必须创建手动静态进度更新。
答案 2 :(得分:0)
使用function 0 = []
function a = function4 (a-1) ++ [a]
连接到firebase以验证凭据
在AsynTask
方法中显示ProgressBar
在onPreExecute()
方法中设置ProgressBar
到GONE
的可见性。
然后,您可以使用OnPostExecute()
让用户知道注册成功。
答案 3 :(得分:0)
试试这个:
//defining firebaseauth object
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initializing firebase auth object
firebaseAuth = FirebaseAuth.getInstance();
//initializing views
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
editTextPassword = (EditText) findViewById(R.id.editTextPassword);
buttonSignup = (Button) findViewById(R.id.buttonSignup);
progressDialog = new ProgressDialog(this); //progress dialog
//attaching listener to button
buttonSignup.setOnClickListener(this);
}
private void registerUser(){
//getting email and password from edit texts
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
//checking if email and passwords are empty
if(TextUtils.isEmpty(email)){
Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this,"Please enter password",Toast.LENGTH_LONG).show();
return;
}
//if the email and password are not empty
//displaying a progress dialog
progressDialog.setMessage("Registering Please Wait...");
progressDialog.show();
//creating a new user
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
//checking if success
if(task.isSuccessful()){
//display some message here
Toast.makeText(MainActivity.this,"Successfully registered",Toast.LENGTH_LONG).show();
}else{
//display some message here
Toast.makeText(MainActivity.this,"Registration Error",Toast.LENGTH_LONG).show();
}
progressDialog.dismiss();
}
});
}
请参阅source code
详细实施