Lock and unlock editing of an EditText

0

In the code snippet below I disable the freight value edition when the freight type is SIF, but the% code_code that should release the editText edition does not work in the following situation: Select SIF and then select FOB. Question How can I release the edition of Library.editTexPermission(edtFrete, true); after blocking it?

        spFrete.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            switch (spFrete.getSelectedItemPosition()) {
                case 0: {  //FOB
                    Library.editTexPermission(edtFrete, true);

                    break;
                }

                case 1: {  //SIF
                    Library.editTexPermission(edtFrete, false);
                    edtFrete.setText("0.0");
                    break;
                }
            }
        }
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

The code snippet of edtFrete with it becomes evident how the edit is blocked now the question is: how to set the KeyListener again?

public static void editTexPermission(EditText editText, Boolean enabled) {
    editText.setFocusable(enabled);
    if (!enabled)
        editText.setKeyListener(null);
}
    
asked by anonymous 13.09.2016 / 14:06

1 answer

4

To block and unblock edittext editing use the setEnabled property of the component, for example:

editText.setEnabled(true);
editText.setEnabled(false);
    
13.09.2016 / 15:13