Bhushan Baviskar
Bhushan Baviskar

Reputation: 53

Want to protect Edit Text from be changed

Here is my code...

            package com.bmc;


            public class Details extends Activity 
            {

                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.details);

                    EditText desc,sol;

            /*
                Some code here...........


             */     desc=(EditText) findViewById(R.id.editText_desc1);
                    sol=(EditText) findViewById(R.id.editText_sol);
                   desc.setEnabled(false);
                   sol.setEnabled(false);
                   sol.setClickable(false);
                   desc.setClickable(false);

                }

            }

Here sol becomes write protected but desc does not. Does anyone have a solution? Thanks.

Upvotes: 1

Views: 638

Answers (3)

dakshbhatt21
dakshbhatt21

Reputation: 3676

Try this, the best way to do it from code. It will also restrict your keyboard to pop up for typing.

Actually it disabled you key stroke on that edittext.

EditText desc = (EditText)findViewById(R.id.editText_desc1);
desc.setKeyListener(null);
EditText sol = (EditText)findViewById(R.id.editText_sol);
sol.setKeyListener(null);

Upvotes: 2

Tony
Tony

Reputation: 10208

Try the following

android:editable="false"

in the edittext.

Upvotes: 2

prolink007
prolink007

Reputation: 34544

Try this:

desc.setEnabled(false);
desc.setClickable(false);
desc.setFocusable(false);
sol.setEnabled(false);
sol.setClickable(false);
sol.setFocusable(false);

Let me know how it goes.

Also, more help here if needed.

Upvotes: 0

Related Questions