error with edittext android java

1

Hello, I want to print by a message toast what I entered in an edit text.

    <EditText
    android:id="@+id/idprodtxxt"
    style="@style/Widget.AppCompat.EditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btn_acceder"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="20dp"
    android:ems="10"
    android:hint="Contraseña"
    android:inputType="textPassword" />

In the java class I am calling it in the following way:

EditText clavetxt; 

clavetxt=(EditText) findViewById(R.id.idprodtxxt);


   btnacceder.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view) {

            if(conf != null) {
                clave = conf.getCLA_S();

                if (clave == clavetxt.getText().toString()) {

                    Intent regis = new Intent(inicio.this, Home.class);///////////////ojoaqui
                    startActivity(regis);
                }
                else{
                    Toast.makeText(inicio.this,"Clave incorrecta"+clave+clavetxt.getText().toString(), Toast.LENGTH_SHORT).show();
                }
            }else{
                Toast.makeText(inicio.this,"Primero configure", Toast.LENGTH_SHORT).show();
            }
        }
    });

    
asked by Yoel Mendoza 04.12.2017 в 02:34
source

1 answer

1

Well the comparison of String that you make is incorrect, you can not compare text strings in that way in Java, string1 == string2. You need to use the equals method

if (clave.equals(clavetxt.getText().toString()))

If you do not mind the upper and lower case you can use:

if (clave.equalsIgnoreCase(clavetxt.getText().toString()))
    
answered by 04.12.2017 / 02:44
source