我试图在我的代码中使用 findViewById,但它必须是无效的,有什么问题?我不想有方法点击按钮,但如果我把它拿出来,它说它必须是无效的。有什么方法可以在不更改代码中的所有内容的情况下做到这一点?
import android.os.Bundle;
import android.app.Activity;
import android.app.NotificationManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class LoginWorker extends Activity implements OnClickListener{
Button login;
EditText user, pass;
ToggleButton repass;
TextView invail;
private boolean savelogin = false;
public void clickbutton() {
login = (Button) findViewById(R.id.bloginf);
user = (EditText) findViewById(R.id.usernametf);
pass = (EditText) findViewById(R.id.passwordtf);
invail = (TextView) findViewById(R.id.invalidinfo);
repass = (ToggleButton) findViewById(R.id.rememberlogintb);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(user.getText().equals("parents")){
if(pass.getText().equals("!saints")){
if(repass.isChecked()){
savelogin = true;
setContentView(R.layout.announcements);
}
}else if(!repass.isChecked()){
savelogin = false;
setContentView(R.layout.announcements);
}
}if(!user.getText().equals("pie")){
invail.setText("Invalid Username and / or Password!");
}if(!pass.getText().equals("!pie")){
invail.setText("Invalid Username and / or Password!");
}
}
});
}
}
谢谢你的时间!