Saehun Sean Oh
Saehun Sean Oh

Reputation: 2281

How to dynamically retrieve string inputs in textField in Android?

I'm trying to create a payment method activity in Android.

I've seen lots of website recognizing my text input (credit card number) DYNAMICALLY so if I put first 3~4 digits, it knows if the card is VISA, MASTER, etc .. before I even finish typing.

What I thought to do was to update the String value I get from getText() method each time an user types. but don't know where to start so far!

Upvotes: 0

Views: 108

Answers (2)

Raghu
Raghu

Reputation: 351

You can attach a listener to the EditText and then override the methods you are interested to take custom actions. Here is an example how you can do it. http://www.mysamplecode.com/2012/06/android-edittext-text-change-listener.html

Good luck

Upvotes: 0

AMC
AMC

Reputation: 130

You can attach to the EditText a listener being notified when the text change, this is natively supported by the android framework: As an example:

editText = (EditText)findViewById(R.id.your_edit_text_id);
textMessage.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(Editable s) {
        //perform checks or implement logic on what the user has entered so far here...
    }
    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
    public void onTextChanged(CharSequence s, int start, int before, int count){}
}); 

Upvotes: 2

Related Questions