我是Android新手,我正在做一個小而簡單的應用程序。我有兩個可編輯EditText和一個名爲Login的按鈕。當我點擊按鈕時,如果EditText的字符串爲空,我想顯示敬酒。這是我的代碼。從Android中的EditableText獲取文本
package com.example.prenotazione_esame;
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.Toast;
import android.view.View.OnClickListener;
public class LoginActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button button_crea = (Button) findViewById(R.id.Create);
button_crea.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
openCreateAccount();
}
});
Button button_login = (Button) findViewById(R.id.Login);
button_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
executeLogin();
}
});
}
private void openCreateAccount(){
Intent intent_crea = new Intent(this, CreateAccountActivity.class);
startActivity(intent_crea);
}
private void executeLogin(){
EditText login_text = (EditText) findViewById(R.id.UserName);
EditText password_text = (EditText) findViewById(R.id.Password);
if ((login_text.getText().toString()=="")|| (password_text.getText().toString() == "")){
Toast toast = Toast.makeText(this, "Inserisci le credenziali di accesso", Toast.LENGTH_SHORT);
toast.show();
}
}
}
問題在哪裏?謝謝。
login_text.getText().toString().equals("")
你檢查它@Gianluca ??? – Lal
嗨,現在我的應用程序運行。謝謝 – Gianluca
很高興它幫助@Gianluca – Lal