我创建登录&注册课。用户应该进入登录页面,但如果他没有帐户,他可以按链接注册页面。不幸的是,当他点击链接时,它会导致一个空白的黑色页面(动作标题就在那里)。没有错误,只要我担心我的代码是正确的(很明显它不是)。这是我的代码
登录
package com.spamcity;
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.TextView;
import android.widget.Toast;
public class login extends Activity {
private EditText email;
private EditText password;
private Button login;
private TextView gosignup;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
setupVariables();
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(login.this, MainActivity.class));
finish();
}
});
gosignup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(login.this, signupActivity.class));
finish();
}
});
}
private void setupVariables(){
email = (EditText) findViewById(R.id.logemail);
password = (EditText) findViewById(R.id.logpassword);
login = (Button) findViewById(R.id.btnLogin);
gosignup = (TextView) findViewById(R.id.textView2);
}
}
注册
package com.spamcity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View.OnClickListener;
public class signupActivity extends Activity {
private EditText idNo;
private EditText fullname;
private EditText email;
private EditText password;
private Button signup;
public class signupScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
setupVariables();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.signup, menu);
Button button = (Button) findViewById(R.id.btnSubmitAction);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Welcome", Toast.LENGTH_SHORT).show();
startActivity(new Intent(signupActivity.this, MainActivity.class));
finish();
}
});
return true;
}
}
private void setupVariables(){
setIdNo((EditText) findViewById(R.id.signidno));
setFullName((EditText) findViewById(R.id.signfname));
setEmail((EditText) findViewById(R.id.signemail));
setPassword((EditText) findViewById(R.id.signpassword));
}
public EditText getIdNo() {
return idNo;
}
public void setIdNo(EditText idNo) {
this.idNo = idNo;
}
public EditText getFullName() {
return fullname;
}
public void setFullName(EditText fullname) {
this.fullname = fullname;
}
public EditText getEmail() {
return email;
}
public void setEmail(EditText email) {
this.email = email;
}
public EditText getPassword() {
return password;
}
public void setPassword(EditText password) {
this.password = password;
}
public Button getSignup() {
return signup;
}
public void setSignup(Button signup) {
this.signup = signup;
}
}
登录xml(转到注册页面的链接)
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnLogin"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:onClick="onClick"
android:clickable="true"
android:text="Sign up if you don't have an account"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="12sp" />
有什么不妥吗?
答案 0 :(得分:0)
因此,您的编辑文本中似乎没有提示。你应该尝试这样的事情:
public void setIdNo(EditText idNo, String idNoHint) {
this.idNo = idNo;
this.idNo.setHint(idNoHint);
}
然后这样称呼:
setIdNo((EditText) findViewById(R.id.signidno), "Enter ID Number");
答案 1 :(得分:0)
您需要将代码移动到父类,没有内部类的目的 在您的情况下, signupActivity 没有逻辑,因此它不会显示任何内容。
您只需删除内部类即可解决此问题。
package com.spamcity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View.OnClickListener;
public class signupActivity extends Activity {
private EditText idNo;
private EditText fullname;
private EditText email;
private EditText password;
private Button signup;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
setupVariables();
Button button = (Button) findViewById(R.id.btnSubmitAction);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Welcome", Toast.LENGTH_SHORT).show();
startActivity(new Intent(signupActivity.this, MainActivity.class));
finish();
}
});
}
private void setupVariables(){
setIdNo((EditText) findViewById(R.id.signidno));
setFullName((EditText) findViewById(R.id.signfname));
setEmail((EditText) findViewById(R.id.signemail));
setPassword((EditText) findViewById(R.id.signpassword));
}
public EditText getIdNo() {
return idNo;
}
public void setIdNo(EditText idNo) {
this.idNo = idNo;
}
public EditText getFullName() {
return fullname;
}
public void setFullName(EditText fullname) {
this.fullname = fullname;
}
public EditText getEmail() {
return email;
}
public void setEmail(EditText email) {
this.email = email;
}
public EditText getPassword() {
return password;
}
public void setPassword(EditText password) {
this.password = password;
}
public Button getSignup() {
return signup;
}
public void setSignup(Button signup) {
this.signup = signup;
}
}
让我知道它是否有效!