I am building an Andoid app where you can enter you credit card info. I want to change the Image next to the edit text depending with what the user typed in real time .
ex: If the number start with 4 it is a visa card.
Any answer will be helpful.
I am building an Andoid app where you can enter you credit card info. I want to change the Image next to the edit text depending with what the user typed in real time .
ex: If the number start with 4 it is a visa card.
Any answer will be helpful.
You can use the listener methods in edit text, as they type update the image you want to edit in afterTextChanged
editText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s)
{
//update view
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
A good link on how the methods work: Android TextWatcher.afterTextChanged vs TextWatcher.onTextChanged
You can use databinding. It will allow you to keep variable sync with any field on your UI.
You will have to add xml property on your view. ex.
android:text="@{viewModel.myText}"
Here is the guide how to implement it: https://developer.android.com/topic/libraries/data-binding/start
You can use library Card Form for credit card input.
<com.braintreepayments.cardform.view.CardForm
android:id="@+id/card_form"
android:layout_width="match_parent"
android:layout_height="match_parent" />
for details https://github.com/braintree/android-card-form