0

I am trying to add a hard coded text in an EditText onClick. Which is OK so far. But the pre-added text is removable. Is there any way to make it Hard coded, so that the user cannot remove it but type in front of it in the same EditText field.

Mohsin Falak
  • 429
  • 6
  • 22
  • 1
    Take a look at this http://stackoverflow.com/questions/19788386/set-unchangeable-some-part-of-edittext-android/19789317#19789317 – antonio Mar 23 '15 at 13:51

2 Answers2

1

You have to use EditText.addTextChangedListener ,by using this you can do the same.

Avishek Das
  • 661
  • 1
  • 6
  • 20
0

you have to use the TextView and EditText inside the Layout and set the EditText and TextView background transparent and set the layout background as EditText bacground

<RelativeLayout
 android:id="@+id/relativeLayout3"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"  
 android:background="@android:drawable/editbox_background" >

<TextView 
  android:id="@+id/constant_text"
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:layout_alignParentLeft="true"
  android:layout_centerVertical="true"
  android:text="HardCodedText"
  android:textAppearance="?android:attr/textAppearanceMedium"
  android:background="@android:color/transparent" />


<EditText 
  android:id="@+id/et_cc"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_toRightOf="@+id/constant_text"
  android:textColor="#000000"  
  android:background="@android:color/transparent"
  android:paddingLeft="5dp"/>
</RelativeLayout>
Furqan
  • 1,417
  • 1
  • 15
  • 22