How to make EditText not editable through XML in Android?

后端 未结 27 1895
梦谈多话
梦谈多话 2020-11-28 17:35

Can anyone tell me how to make an EditText not editable via XML? I tried setting android:editable to false, but

  1. it is de
27条回答
  •  日久生厌
    2020-11-28 18:19

    I resolve this with a dialog.

        AlertDialog dialog;
        EditText _editID;
        TextView _txtID;
    
     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_principal);
            _txtID = (TextView) findViewById(R.id._txtID);
            dialog = new AlertDialog.Builder(this).create();
            _editID = new EditText(this);
            _editID.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED);
            dialog.setTitle("Numero do Registro:");
            dialog.setView(_editID);
            dialog.setButton(DialogInterface.BUTTON_POSITIVE, "IR", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    _txtID.setText(_editID.getText());
                    toId(Integer.parseInt((_editID.getText().toString())));
                }
            });
            dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "CANCELAR", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    
            _txtID.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    _txtID.setText("_editID.getText()");
                    //_editID.setText("");
                    dialog.show();
    
                }
            });
    

提交回复
热议问题