Question

I have an EditText with 140 characters maximum length for typing. Now I have one button, when I click the button, the contents of the edit text should be printed on log cat. Up to this I have implemented.

But my question is, I should validate for words which means a continuous text without meaning (for eg. "ajldjlkdjkjfdjdjjd") should not be printed instead words should be checked say word length of 10 approx. for grammar. How to implement this ? any ideas would be helpful for me. thanks in advance.

Note:- I may type word as well as numbers, if i typed word without meaning it should alert a message.

Was it helpful?

Solution

You can use below code snippet for that. add your code when length is proper or not.

    //Prepare object of Edit Text
    EditText editText = (EditText) findViewById(R.id.editText1);
    //Get String entered by user
    String enteredText = editText.getText().toString();
    //split string to get every word using _ (space) and add all word to an array
    String[] words = enteredText.split(" ");
    for (int i = 0; i < words.length; i++) {
        if (words[i].length() > 10) {
            //handle if any word is > 10 ch.
            break;
        }else{
             //handle if word is meaning full or not
        }
    }

OTHER TIPS

There's no easy way to achieve this.(Frankly speaking almost impossible.)

One solution could be - keep a local DB with a list of words, sorted based on word length.

Now, each time you get some text from the edit text, check the size of the String . If it is equal to 10, start by comparing all the words which have length = 10 in the DB. YOU CANNOT COMPARE SUBSETS OF ENTERED TEXT.

example knowledge can be seen as know, now, ledge,edge ,led,owl etc..

You'll have to implement your own (complex) logic for a word-subset lookup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top