I got this situation that i have to find *
and replace with editable text for example: "HI *, What your order * some text. some more text * after". Now i need output like this Hi ____, What your order ____ some text. some more text ___ after
how can i achieve this in Android please help thanks.

- 669
- 6
- 16
-
You want '_' in place of '*' ? – Ankita Dec 20 '17 at 04:43
-
Add an example of input String and output String . Cause i don't get what exactly you want to achieve. – ADM Dec 20 '17 at 04:46
-
you can find many of solution to do that u want: https://stackoverflow.com/questions/5754363/android-how-to-replace-part-of-a-string-by-another-string – ND1010_ Dec 20 '17 at 04:53
-
@Ankita Those dashed i want to input text from user, i'll get template with stars in it and i need to replace with editable text – Hemanth S Dec 20 '17 at 04:55
2 Answers
Firstly Spit the strings by using this post :-
And then add edittext after each string to show output like yours.

- 1,701
- 2
- 17
- 33
This is Easy dude!
Just store your template in Preference, then take values from user and show it back to user with template.
For example; i Stored following in Preference: I used specific keywords here to differentiate user's response:
Hi (name), What your order (order) some text. some more text (other) after
where (name) is for user's name;
(order) is for user's order; and
(other) is for other info.
Now, take input from User by some Input field form, and use preference like this.
String mTemplate = "Hi (name), What your order (order) some text. some more text (other) after";
Replace keywords with user's response like this;
mTemplate.replace("(name)","UserName_goes_here").replace("(order)","UserOrder_goes_here").replace("(other)","OtherInfo_goes_here");
Here, you'll get strings with your template. Hope this helps you.

- 1,895
- 1
- 13
- 30
-
I need to show full text with `EditText` in between, i want user to type data in `EditText` fields. Your method is good for constant template but i have dynamic template coming from internet and need to show like that – Hemanth S Dec 20 '17 at 07:30