Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>[EDIT] I made a mistake earlier, because, to get the text, you need to use .getText().toString().</p> <p>Here is a full working example:</p> <pre><code>package com.psegina.passwordTest01; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Toast; public class Main extends Activity implements OnClickListener { LinearLayout l; EditText user; EditText pwd; Button btn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); l = new LinearLayout(this); user = new EditText(this); pwd = new EditText(this); btn = new Button(this); l.addView(user); l.addView(pwd); l.addView(btn); btn.setOnClickListener(this); setContentView(l); } public void onClick(View v){ String u = user.getText().toString(); String p = pwd.getText().toString(); if( u.equals( p ) ) Toast.makeText(getApplicationContext(), "Matches", Toast.LENGTH_SHORT).show(); else Toast.makeText(getApplicationContext(), user.getText()+" != "+pwd.getText(), Toast.LENGTH_SHORT).show(); } } </code></pre> <p>Original answer (Will not work because of the lack of toString())</p> <p>Try using .getText() instead of .toString().</p> <pre><code>if( passw1.getText() == passw2.getText() ) #do something </code></pre> <p>.toString() returns a String representation of the whole object, meaning it won't return the text you entered in the field (see for yourself by adding a Toast which will show the output of .toString())</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload