Problem?
How does the Android EditText control prohibit entering content inside?
Modified version of the workaround:
EditText EditText = (EditText) Findviewbyid (R.ID.EDITTEXT1);
Edittext.setkeylistener (NULL);
It may be a bit strange to see this question, EditText's function is not to write to the above content?
Furthermore, if you really want to prevent text from being entered, add android:focusable= "false" to the layout file,
or use Edittext.setfocusable (FALSE) in your code, OK?
Project requirements are like this, if the edittext above has been settext () content, you need to prohibit the input, to prevent it from being modified.
If no content is displayed, the EditText is set to an input state.
The test verifies that the effect of the Setfocusable method is only valid for the first time use, that is, if the layout file is set:
Android:focusable= "False" even if you set this control property in code: Edittext.setfocusable (True), and it cannot be edited.
The setfocusable scheme is not feasible. After exploring the feasible solution.
Use Edittext.setinputtype (inputtype.type_null) to disable the phone's soft keyboard.
Edittext.setinputtype (Inputtype.type_class_text); To turn on the soft keyboard.
The application is enabled by default.
Special Note: This method can only prohibit the soft keyboard, if the phone comes with a hard keyboard, this scheme is invalid.
Test demo included:
public class Edittexttest extends Activity
{
/** test EditText forbid input function demo */
EditText EditText;
Boolean flag = true;
public void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
EditText = (editText) Findviewbyid (R.ID.EDITTEXT1);
Button btn = (button) Findviewbyid (R.id.button1);
Btn.setonclicklistener (New Onclicklistener ()
{
public void OnClick (View v)
{
if (flag==true)
{
System.out.println ("Open soft keyboard");
Edittext.setinputtype (Inputtype.type_class_text);
Flag = false;
}else
{
System.out.println ("No soft keyboard");
Edittext.setinputtype (Inputtype.type_null);
Flag = true;
}
}
});
}
}
This article is from the "No Water Fish" blog, please be sure to keep this source http://javaqun.blog.51cto.com/10687700/1708753
How the Android edittext control prevents input content