こんにちは私は次のような活動をしました
....
<TableRow >
<TextView
android:text="@string/userName"
android:width ="100dp" />
<EditText
android:id="@+id/txt_userName"
android:width="100dp"
android:hint="@string/userName" />
</TableRow>
<TableRow>
<TextView
android:text="@string/password" />
<EditText
android:id="@+id/txt_password"
android:inputType="textPassword"
android:hint="@string/password" />
</TableRow>
....
これが私のクラスです
public class LoginActivity extends Activity {
private boolean rememberpassword = false;
ProgressDialog dialog = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Button btn_logIn = (Button)findViewById(R.id.btn_signIn );
btn_logIn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
showProgressDialog();
getUserCredentials();
}
}); //end of anonymous class
} //end of onCreate
private void showProgressDialog() {
dialog = new ProgressDialog(this);
dialog.setMessage("Please Wait. Your authentication is in progress");
dialog.setButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}); //end of anonymous class
} //end of showProgressDialog()
private void getUserCredentials() {
EditText txt_userName = (EditText) findViewById(R.id.txt_userName);
String userName = txt_userName.getText().toString();
EditText txt_password = (EditText) findViewById(R.id.txt_password);
String password = txt_password.getText().toString();
if (userName != null && !userName.trim().equals("") && password != null && !password.trim().equals("")) {
dialog.show();
callWebServide(userName, password);
} else if (userName == null) {
Toast.makeText(this, "User Name is required", Toast.LENGTH_LONG).show();
} else if (password == null && password.trim().equals("")) {
Toast.makeText(this, "Password is required", Toast.LENGTH_LONG).show();
}
} //end of getUserCredentials()
} //end of class LoginActivity
まず、私の両方の条件が機能していません
} else if (userName == null) {
Toast.makeText(this, "User Name is required", Toast.LENGTH_LONG).show();
} else if (password == null && password.trim().equals("")) {
Toast.makeText(this, "Password is required", Toast.LENGTH_LONG).show();
}
アクティビティが起動すると、editTextにヒントが表示されます。ログインボタンをクリックすると、パスワードまたはユーザー名が必要であることがトーストに表示されます。しかし、そうではありません:(。2番目に使用した
if (userName != null && !userName.trim().equals("") && password != null && !password.trim().equals("")) {
dialog.show();
callWebServide(userName, password);
}
ユーザー名とパスワードが空であってはならない場合にのみダイアログが表示されますが、ログインボタンをクリックするとすぐにダイアログが表示され始め、ヒントのみがeditTextに表示されます。私はクリックでそれについて言及しませんでしたdialog.show()
。ダイアログを作成していますが、表示されていません。
なぜ予期しない動作をしているのですか?私は何か間違ったことをしていますか?
ありがとう