How to set maxLenght for textfield for android?

You must Login before you can answer or comment on any questions.

Hi, I'm trying to set the maxLenght for textfiled but its not implanting on the while running the app.

this is my code:

" var tfadd = Ti.UI.createTextField({

width: 200,

height: 50, top: 220,

right: 60,

maxLength:25,

font:{fontsize:12},

hintText : 'Please enter your Address',

softKeyboardOnFocus : Ti.UI.Android.SOFT_KEYBOARD_DEFAULT_ON_FOCUS, // Android only

keyboardType : Ti.UI.KEYBOARD_DEFAULT,

returnKeyType : Ti.UI.RETURNKEY_DEFAULT,

borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED

});

"

3 Answers

Accepted Answer

Hello Pratik,

android creates problem also with their properties many times.

if maxLength is not working then you can use custom solution for that like

check Text length at it's change event...

tfadd.addEventListener('change', function(e) {
 
    if (e.value.length > 25)
        e.source.value = e.source.oldValue;
    else
        e.source.oldValue = e.value;
});
Best Luck...

Thanks a lot Sarafaraz Babi..

its work for me...

— answered 7 months ago by Pratik Jayswal
answer permalink
1 Comment
  • welcome Pratik...and one thing i am requesting you to please use the comment facility for the discussion purpose.if you have another answer then and then only write it as answer and create new question everytime if you have new query so this way our community will became strong....Thanks !

    — commented 7 months ago by Sarafaraz Babi

Hi Sarafaraz,

Need one more help..

Can you just help me for auto increment data in my textfiled..

i.e if in database having one row data and its id is 1, now when i select new insert data the text field area should automatically increase by one..

thanks in advance...

— answered 7 months ago by Pratik Jayswal
answer permalink
2 Comments
  • sure pratik i will help you...just create new question and post some code that how you are doing now...so this way some other's also can help you..if they know answer..

    for that i think you can take one variable like count and keep this count++; or Parse the textvalue into int and then keep it +1 increament and set into textfield.

    — commented 7 months ago by Sarafaraz Babi

  • Hi,

    I'm added the ques already on

    below is the link

    http://developer.appcelerator.com/question/144134/auto-increment-id-code-for-text-field-when-connected-to-database#comment-145497

    — commented 7 months ago by Pratik Jayswal

Your Answer

Think you can help? Login to answer this question!