Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all :)

I have a problem with this code

when I try to login without database, it make no action

here is the .Java File

Java
package com.msagroup.sbhmg;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LogIn extends Activity {
	
	Button _gotousermain;
	EditText _etmail;
	EditText _etpassword;
	String _email;
	String _pass;
	TextView _tvcomm;

	@Override
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        
        
        _gotousermain = (Button) findViewById(R.id.btnlogin);
        _etmail = (EditText) findViewById(R.id.etmail);
        _etpassword = (EditText) findViewById(R.id.etpassword);
        _tvcomm = (TextView) findViewById(R.id.tvcomment);
        
        _gotousermain.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				//startActivity(new Intent(LogIn.this, UserMain.class));
				
					_email = _etmail.getText().toString();
					_pass =  _etpassword.getText().toString();
					if(_email == "user@user.com" && _pass == "123")
					{
						startActivity(new Intent(LogIn.this, UserMain.class));
					}
					else
					{
						if(_email == "admin@admin.com" && _pass == "123")
						{
							startActivity(new Intent(LogIn.this, AdminMain.class));
						}
						else
						{
							_tvcomm.append("@string");
						}
					}
				//} 
				//catch (Exception e) {
				//}
				//finally
				//{
				//	
				//}
		        
				
			}
		});
        
	
	}
}



and here is the .XML file:

XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/etmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="41dp"
        android:hint="@string/email"
        android:inputType="textEmailAddress" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/etpassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/etmail"
        android:layout_marginTop="16dp"
        android:hint="@string/password"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/btnlogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/etpassword"
        android:layout_marginTop="16dp"
        android:text="@string/login" />

    <Button
        android:id="@+id/btnregistration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btnlogin"
        android:layout_marginTop="70dp"
        android:text="@string/registration" />

    <Button
        android:id="@+id/btnbacktomain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/btnregistration"
        android:layout_alignBottom="@+id/btnregistration"
        android:layout_alignParentRight="true"
        android:text="@string/backtomain" />

    <TextView
        android:id="@+id/tvcomment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="@string/invalidlogin"
        android:visibility="invisible"/>

</RelativeLayout>




thank you all :)
Posted

Replace your If statement with this

Java
if(_email.equals("user@user.com") && _pass.equals("123")


We use == only in int values and for string we use .equals

Try this in your code.
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900