I am creating a method to validate my login fields (user name and password). I have created a method and call it on click event but it is not working.
package com.boyzcorn.android.fyp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/** Called when the activity is first created. */
public class login extends Activity {
EditText eText = (EditText)findViewById(R.id.uid);
EditText eText2 = (EditText)findViewById(R.id.editText2);
Button btnSubmit = (Button)findViewById(R.id.sbtn);
Button btnSignup = (Button)findViewById(R.id.signupbtn);
/* I think there is some problem with my method definition but i am not
getting it. */
public void validation(EditText username,EditText pass) {
if (username.getText().toString().equals("") ||
pass.getText().toString().equals("")) {
Toast.makeText(
getApplicationContext(),
"Fill Empty Fields",Toast.LENGTH_SHORT
).show();
} else {
Intent i = new Intent(login.this,order_pushing.class);
startActivity(i);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
btnSubmit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
validation(eText,eText2);
}
});
btnSignup.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(login.this,signup.class);
startActivity(i);
}
});
}
}
Put this code under Activity{
EditText eText;
EditText eText2;
Button btnSubmit;
Button btnSignup;
and initialize it in OnCreate after setContentView(R.layout.login);
eText = (EditText)findViewById(R.id.uid);
eText2 = (EditText)findViewById(R.id.editText2);
btnSubmit = (Button)findViewById(R.id.sbtn);
btnSignup = (Button)findViewById(R.id.signupbtn);
Hope This will work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With