简体   繁体   中英

How to add a permanent text which is tappable and editable along with hint, which user can change in EditText of android?

I looked on google but didn't find what exactly i am looking for.

I want a edit text to have text or image which i can change by tapping it and selecting new text or image. Also i want hint followed by that text or image.

I tried multiple experiment and was able to add text(by changing selection location and adding text) and image(using drawable addition from android code)

For text :

edt.setText("Fixed Text");
Selection.setSelection(edt.getText(), edt.getText().length());

Image through XML:

android:drawableLeft="@drawable/ic_launcher"

But when i add text, i won't be able to add hint. In case of image hints get added. Also i want my permanent text and image to be tappable and updatable.

Any help would be really helpful. I want $ to be fixed and tappable, and want to change it to different currency. but want 52.63 to be hint and can be editable by user tap.

EDIT to give more clarity:

Example: i want to add part of the text as permanent and part as hint for example $ 52, so $ is permanent and not editable through user, he can select it through list view by tapping on $, but 52 he can change using android keyboard.

在此处输入图片说明

I am not quite sure about the whole part about the image being placed into the EditText as a hint, but if you wanted to create the $52.63 as a hint in the EditText, all you would have to do is:

    edt.setHint("$52.63"); 

in your onCreate() method. I am not sure if this is what you are looking for, but this is a simple way to add a hint to a textEdit. If you wanted the hint to change when the user tapped the screen or something like that, I would look into adding a tap listener of the android component that you desire to be tapped to change the hint, and then modify the hint using the method above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM