-1

I want to have an edittext that has an uneditable text beside it (on the left, the beginning of the EditText). Just like this one, How do I go with this?

EditText with a text beside it

LogicStuff
  • 19,397
  • 6
  • 54
  • 74
J. Salonga
  • 13
  • 1

2 Answers2

0

Put constant text inside EditText which should be non-editable - Android

I found this useful for those who wanted it. I haven't applied it yet but this would work, right?

Community
  • 1
  • 1
J. Salonga
  • 13
  • 1
0
final EditText edt = (EditText) findViewById(R.id.editText1);

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


edt.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            if(!s.toString().contains("http://")){
                edt.setText("http://");
                Selection.setSelection(edt.getText(), edt.getText().length());

            }

        }
    });

try this....

Shivanshu Verma
  • 609
  • 5
  • 19