TheMohican
TheMohican

Reputation: 87

Add a character in an EditText

I need to add a character "S" right after the last written number in an EditText (Oe) so:

if i write i number : "123", it must send "123S" instead. If i write "1234", it must send "1234S" instead.

How to do that ?

my code:

((Button) findViewById(R.id.btn_write_HRM_Noty)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) 
        {
            str = Oe.getText().toString();
            str = str.substring(0, 0) + "G" + str.substring(0, str.length());
            mService.enableHRNotification(mDevice, str);
        }
    });

Upvotes: 1

Views: 98

Answers (3)

user1889890
user1889890

Reputation:

1) Make a new string including by putting together the edittext and the character you want to add finalString = (string + "s"). Then use the setText()method to change the contents shown in the edittext

2) You could do this directly after the user enters something in the text box (after it loses focus or they finish typing and go to the next field)

Check this thread out: How can i know when a edittext lost focus

Upvotes: 0

Steve P.
Steve P.

Reputation: 14699

I'm a little confused. Are you simply asking how to add a character to a string? If so: str+='S'; will work. Then you simply add the string back to the EditText with .setText(str) or simply put it back into your notification with 'S' added (as Blundell suggested).

Upvotes: 1

Blundell
Blundell

Reputation: 76458

 mService.enableHRNotification(mDevice, str + "S");

Upvotes: 0

Related Questions