Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3680546
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:35:21+00:00 2026-05-19T03:35:21+00:00

Im trying to compare the values of two edittext boxes. What i would like

  • 0

Im trying to compare the values of two edittext boxes. What i would like is to just compare passw1 = passw2. As my code is now comparing two strings i have entered as i could not get to compare them.

 final EditText passw1= (EditText) findViewById(R.id.passw1);
 final EditText passw2= (EditText) findViewById(R.id.passw2);
 Button buttoks = (Button) findViewById(R.id.Ok);
      buttoks.setOnClickListener(new OnClickListener() {    

    public void onClick(View v) {       

     if (passw1.toString().equalsIgnoreCase("1234") && passw2.toString().equalsIgnoreCase("1234")){
      Toast.makeText(getApplication(),"Username and password match", Toast.LENGTH_SHORT).show();
      }
    else {
        Toast.makeText(getApplication(),"Username and password doesn't match", Toast.LENGTH_SHORT).show();
      }
     }   }); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:35:22+00:00Added an answer on May 19, 2026 at 3:35 am

    [EDIT]
    I made a mistake earlier, because, to get the text, you need to use .getText().toString().

    Here is a full working example:

    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();
        }
    }
    

    Original answer (Will not work because of the lack of toString())

    Try using .getText() instead of .toString().

    if( passw1.getText() == passw2.getText() )
    #do something
    

    .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())

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two decimal values in Java script. I have two
I'm trying to compare two arrays and get only the values that exist on
I'm trying to use simpletest to compare two numeric strings, one from an array
I am trying to compare two different arrays. I am looking for the values
I have the following problem. I am trying to compare two datetime values in
I'm trying to compare two millisecond values in Java. One from a calendar, and
I'm trying to compare two VARIANT values in VC++ using the VarCmp function: VARIANT
Following is Objective-C code where I'm trying to do a compare between two NSString
I'm trying to find a nice way to compare two strings when reading line
Im trying to compare these two chars but on win 32 Visual Studio 2008:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.