Answer the question
In order to leave comments, you need to log in
Why is the text repeated on the page?
Good afternoon. I have such a problem. There is a phone number verification page through firebase.
On the number confirmation page where you need to enter the code, there is a repeating text.
VerifyActivity
public class VerifyOTPActivity extends AppCompatActivity {
private EditText inputCode1, inputCode2, inputCode3, inputCode4, inputCode5, inputCode6;
private String verificationId;
private static String global_url = AppConst.Server_url;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verify_o_t_p);
context = VerifyOTPActivity.this;
TextView textMobile = findViewById(R.id.textMobile);
textMobile.setText(String.format(
"+7" + getIntent().getStringExtra("mobile")
));
inputCode1 = findViewById(R.id.inputCode1);
inputCode2 = findViewById(R.id.inputCode2);
inputCode3 = findViewById(R.id.inputCode3);
inputCode4 = findViewById(R.id.inputCode4);
inputCode5 = findViewById(R.id.inputCode5);
inputCode6 = findViewById(R.id.inputCode6);
setupOTPInputs();
final ProgressBar progressBar = findViewById(R.id.progressBar);
final Button buttonVerify = findViewById(R.id.buttonVerify);
verificationId = getIntent().getStringExtra("verificationId");
buttonVerify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(inputCode1.getText().toString().trim().isEmpty()
||inputCode2.getText().toString().trim().isEmpty()
||inputCode3.getText().toString().trim().isEmpty()
||inputCode4.getText().toString().trim().isEmpty()
||inputCode5.getText().toString().trim().isEmpty()
||inputCode6.getText().toString().trim().isEmpty()){
Toast.makeText(VerifyOTPActivity.this, "Please enter valid code!", Toast.LENGTH_SHORT).show();
return;
}
String code = inputCode1.getText().toString() +
inputCode2.getText().toString() +
inputCode3.getText().toString() +
inputCode4.getText().toString() +
inputCode5.getText().toString() +
inputCode6.getText().toString();
if(verificationId != null){
progressBar.setVisibility(View.VISIBLE);
buttonVerify.setVisibility(View.INVISIBLE);
PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(
verificationId,
code
);
FirebaseAuth.getInstance().signInWithCredential(phoneAuthCredential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
buttonVerify.setVisibility(View.VISIBLE);
if(task.isSuccessful()){
Intent intent = new Intent(getApplicationContext(), SubscribeActivity.class);
intent.putExtra("account_type","customer");
intent.putExtra("mobile", textMobile.getText().toString());
startActivity(intent);
} else{
Toast.makeText(VerifyOTPActivity.this, "The verification code entered was invalid!", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
findViewById(R.id.textResendOTP).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
"+7" + getIntent().getStringExtra("mobile"),
60,
TimeUnit.SECONDS,
VerifyOTPActivity.this,
new PhoneAuthProvider.OnVerificationStateChangedCallbacks(){
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
Toast.makeText(VerifyOTPActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
@Override
public void onCodeSent(@NonNull String newVerificationId, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
verificationId = newVerificationId;
Toast.makeText(VerifyOTPActivity.this, "OTP sent", Toast.LENGTH_SHORT).show();
}
}
);
}
});
}
private void setupOTPInputs(){
inputCode1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().trim().isEmpty()){
inputCode2.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputCode2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().trim().isEmpty()){
inputCode3.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputCode3.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().trim().isEmpty()){
inputCode4.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputCode4.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().trim().isEmpty()){
inputCode5.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputCode5.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().trim().isEmpty()){
inputCode6.requestFocus();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question