Reputation: 87
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
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
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