My question is: Is it possible to enable copy text function from a disabled editText ?
I've tried the following code to test the behaviour on Android 4.4.2 (samsung Galaxy Note II)
EditText _edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment_test);
_edit = (EditText) findViewById(R.id.editDisabled);
_edit.setText("Text to be copied...");
_edit.setEnabled(false);
/* update code with answer below */
_edit.setInputType(InputType.TYPE_NULL);
_edit.setTextIsSelectable(true);
/* end mod */
Toast.makeText(getApplicationContext(), "onClick enabled: " + (_edit.isClickable() ? true : false) +
" \n onLongClick enabled: " + (_edit.isLongClickable() ? true : false) , Toast.LENGTH_LONG).show();
_edit.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View paramView) {
Toast.makeText(getApplicationContext(), "onLongClick()!!!", Toast.LENGTH_LONG).show();
return false;
}
});
_edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View paramView) {
Toast.makeText(getApplicationContext(), "onclick()!!", Toast.LENGTH_LONG).show();
}
});
}
When the activity is open, the Toast displays true/true for the onClick() and onLongClick() events. But if I try to click or longClick on the disabled editText no one event is fired..
So is anyone able to answer to my question or explain the strange behaviour of the disabled editText?
Thank you in advance