我正在尝试构建一个firebase身份验证,而我的类实现了View.OnClickListener
但是当点击视图时没有任何反应,有什么帮助吗?
这是我的代码
private void updateUI(int i) {
if(i == R.id.tv_not_member){
mLoginButton.setVisibility(View.GONE);
mNotMemberTV.setVisibility(View.GONE);
mUsernameField.setVisibility(View.VISIBLE);
mRegisterButton.setVisibility(View.VISIBLE);
mNotMemberTV.setVisibility(View.VISIBLE);
} else if (i == R.id.tv_member){
mUsernameField.setVisibility(View.GONE);
mRegisterButton.setVisibility(View.GONE);
mNotMemberTV.setVisibility(View.GONE);
mLoginButton.setVisibility(View.VISIBLE);
mNotMemberTV.setVisibility(View.VISIBLE);
}
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.btn_email_create_account) {
createAccount(mEmailField.getText().toString(), mPasswordField.getText().toString());
} else if (i == R.id.btn_email_sign_in) {
signIn(mEmailField.getText().toString(), mPasswordField.getText().toString());
} else if(i == R.id.tv_not_member){
updateUI(i);
} else if (i == R.id.tv_member){
updateUI(i);
}
}
}
答案 0 :(得分:0)
您需要为视图指定onClickListener。
例如:
textView.setOnClickListener(本);
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private TextView TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialiseViews();
initialiseListeners();
}
public void initialiseViews() {
textView = (textView) findViewById(R.id.text_view);
}
public void initialiseListeners() {
textView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.text_view:
// do here
break;
}
}
}