我想在用户填写用户名和密码字段后,在我的登录活动中更改我的登录按钮的样式。只是向用户显示该按钮现在已启用..
mLogIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Username,Password;
Username = mUserName.getText().toString();
Password = mPassword.getText().toString();
if(Username.length() == 0) {
Toast.makeText(getApplication(),"enter username",Toast.LENGTH_SHORT).show();
} else if(Password.length() == 0) {
Toast.makeText(getApplication(),"enter password",Toast.LENGTH_SHORT).show();
} else if(Username.length() != 0 && Password.length() != 0) {
mLogIn = (Button) findViewById(R.id.login_btn);
mLogIn.setBackgroundResource(R.drawable.btn_bg);
}
}
});
我试过了..但是点击后它会发生变化..还有其他任何建议......
答案 0 :(得分:0)
像这样使用:
CREATE TRIGGER patientTrigger
BEFORE INSERT ON tbl_patient
FOR EACH ROW
SET NEW.idPatient = CONCAT("PAS-",COALESCE((SELECT MAX(id)+1 from tbl_patient),1));
CREATE TRIGGER ageTrigger
BEFORE INSERT ON tbl_pasien
FOR EACH ROW
SET NEW.age = YEAR(CURDATE()) - YEAR(birthDate);
答案 1 :(得分:0)
您是在构建原生应用还是混合应用?如果是后者,请尝试以下代码:
在你的JS中,这样做:
function Enabled(){
var us = $('#user').val();
var pa = $('#pass').val();
if(us!=='' && pa!==''){
$('#buttonid').prop('disabled',false);
}
}
在你的HTML中执行此操作:
<input type="text" id="user" onclick="Enabled();">
<input type="password" id="pass" onclick="Enabled();">
<button disabled id="buttonid" >Click Me</button>
注意:确保您的<head>
标记中包含jQuery。 E.g。
<script src="jQuery-2.0.0" charset="utf-8"></script>
答案 2 :(得分:0)
我建议最初禁用登录按钮,例如通过xml android:enabled="false"
或通过代码。然后在用户名和密码中添加TextWatcher
,并在字段为非空时启用登录按钮:
public class Example extends Activity implements View.OnClickListener, TextWatcher {
EditText mUserName;
EditText mPassword;
Button mLogIn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
mUserName = (EditText)findViewById(R.id.username);
mPassword = (EditText)findViewById(R.id.password);
mLogIn = (Button)findViewById(R.id.login_btn);
mUserName.addTextChangedListener(this);
mPassword.addTextChangedListener(this);
mLogIn.setOnClickListener(this);
mLogIn.setEnabled(false); // TODO the saved state may break here things.
}
@Override
public void onClick(View v) {
// TODO the login
}
@Override
public void afterTextChanged(Editable s) {
mLogIn.setEnabled(mUserName.getText().length() > 0 && mPassword.getText().length() > 0);
}
// not used:
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override public void onTextChanged(CharSequence s, int start, int before, int count) {}
}