Can we have uneditable text in edittext

I am using an EditText. Is it possible to have a part of text uneditable and the rest editable in the same EditText?

  • How to set position in spinner?
  • Get Width and Height of one row in RecycleView - Android
  • Convert the android app in Google Play for Samsung Store
  • Self-signed certificate and loopj for Android
  • Reduce size of debug APK in IntelliJ
  • Android Gradle app:connectedCheck runs tests from dependencies
  • Related posts:

    Ways to guess if C2DM is connected
    OnItemClickListener using ArrayAdapter for ListView
    Android Bluetooth socket freeze application
    What is the integer value that gives a broadcast receiver highest priority?
    Using tesseract on android
    Android Debugging Tips
  • Android AudioRecord Supported Sampling Rates
  • TLS 1.1, 1.2 in WebView for android <= 4.3
  • Android : How do I update my textView in a Fragment
  • MultiSelect gesture like Google Photos app
  • Delete key in Translations Editor
  • How to finish current activity in Android
  • 2 Solutions collect form web for “Can we have uneditable text in edittext”

    You could use

    editText.setFocusable(false);

    or

    editText.setEnabled(false);

    although disabling the EditText does currently not ignore input from the on-screen keyboard (I think that’s a bug).

    Depending on the application it might be better to use an InputFilter that rejects all changes:

    editText.setFilters(new InputFilter[] {
        new InputFilter() {
            public CharSequence filter(CharSequence src, int start,
                int end, Spanned dst, int dstart, int dend) {
                return src.length() < 1 ? dst.subSequence(dstart, dend) : "";
            }
        }
    });

    Also see this question.

    You can implement a TextChangedListener where you make sure those parts of your text wont get deleted/overwritten.

    class TextChangedListener implements TextWatcher {
        public void afterTextChanged(Editable s) {
                    makeSureNothingIsDeleted();
        }
    
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
    
        public void onTextChanged(CharSequence s, int start, int before, int count) {}
    }
    

        TextChangedListener tcl = new TextChangedListener();
        my_editable.addTextChangedListener(tcl);
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.