0

I am getting the keyss from the firebase database as :

                promoCodeKey = history.getKey();

it is giving me output as T20 Test10 etc as string

I want to save it in an array to check from the editText if the user enters any text and if the text matches any of the key

How can i achieve this?

I want to check from each key.

1 Answer 1

1

You could use String split function.

String keysString = history.getKey();

//removes all "Key promo is" text
String replaceString=keysString.replace("Key promo is","");   
// removes all white spaces
String trimString = replaceString.replaceAll("\\s+",""); 

String[] keys = trimString.split(".");
for (int i = 0; i < keys.lenght; i++) {
    if (keys[i] == editText.getText()) {
        return true;
    }
}
Sign up to request clarification or add additional context in comments.

9 Comments

I cannot add the values manually. i have to take it from the database because it will change accordingly. And i dont want to split it. I want to check from each key if it matches the text in the EditText that user enters @Ban Markovic
Does your function "history.getKey()" returns string which is formatted like "T20 Test10"?
You can than split it into String array. And than with for loop iterate through every key and check if it matches the EditText input? I updated my response, please check.
Hi, I cleaned now your string. So this code removes unnecessary text, and than removes white space, which leaves "." as separator between key elements.
I thought you need to separate them, so you can check for each if it matches user input?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.