Android CCTexFieldTTF char limit issue

Hi,

I am working on a game which will run on IOS and Android devices. For IOS its complete, but on Android only the work that is pending is to get text input working properly.

There are some conditions for text input like:

  1. User can only input characters(a-z,A-Z).
  2. The length of the characters should not exceed 7.

The code for satisfying this two conditions is below:

bool CEnterNameLayer :: onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen)
{
    // if insert enter, treat as default to detach with ime
    if ('\n' == *text)
    {
        return false;
    }

    /* 
       a = 97 z = 122
       A = 65 Z = 90
    */
    int c = *(text);

    if(c < 65 || (c > 90 && c < 97) || c > 122)
        return true;

    // if the textfield's char count more than CHAR_LIMIT, doesn't insert text anymore.
    if (pSender->getCharCount() >= CHAR_LIMIT) // CHAR_LIMIT = 7
    {
        return true;
    }

    return false;
}

The above code works perfectly on IOS devices but not on Android.

On Android it accepts all characters and also i am not able to control the number of characters. I have checked TextInputTest but that is also not working on Android.

I am using cocos2d-1.0.1-x-0.13.0.
I am testing it on Android OS 2.2.

I am not able to understand what is going wrong. Please help me out or point me into the right direction.

Thank you.

Hi did you found any solution ???

I am also facing the same problem… i try changing the afterTextChanged function in cocos2dxGLSurfaceView.java but it doesn’t work… i am new to android development…

plz plz do reply

Kaushik Poria wrote:

Hi,
>
I am working on a game which will run on IOS and Android devices. For IOS its complete, but on Android only the work that is pending is to get text input working properly.
>
There are some conditions for text input like:
>

  1. User can only input characters(a-z,A-Z).
  2. The length of the characters should not exceed 7.
    >
    The code for satisfying this two conditions is below:
    >
    […]
    >
    >
    The above code works perfectly on IOS devices but not on Android.
    >
    On Android it accepts all characters and also i am not able to control the number of characters. I have checked TextInputTest but that is also not working on Android.
    >
    I am using cocos2d-1.0.1-x-0.13.0.
    I am testing it on Android OS 2.2.
    >
    I am not able to understand what is going wrong. Please help me out or point me into the right direction.
    >
    Thank you.

i have the same problem. i can’t solve that, almost a month.
if you have any suggestions or ideas that please reply…

seihee han wrote:

i have the same problem. i can’t solve that, almost a month.
if you have any suggestions or ideas that please reply…

I ended up modifying the “Cocos2dxGLSurfaceView.java” file.
It has the reference of the TextField and Callbacks.