我在布局中有一个“登录”xml。我有另一个xml是“列表”。
在我的应用程序中,用户使用电子邮件地址和密码登录应用程序,而不是显示其邮件列表。我这样做了:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
LoginScreen();
}
// I am receiving the email and password on the main layout for login page
public void LoginScreen()
{
setContentView(R.layout.main);
EditText emailTxt = (EditText) findViewById(R.id.txtMail);
EditText passwordTxt = (EditText) findViewById(R.id.txtPassword);
String email= epostaTxt.getText().toString();
String password = parolaTxt.getText().toString();
// After receive, call the MailList() for connection and getting the list
MailList()
}
// and I use this email and password again into the MailList() for connection with server then receive the mail list
public void MailList()
{
setContentView(R.layout.list);
EditText emailTxt = (EditText) findViewById(R.id.txtMail);
EditText passwordTxt = (EditText) findViewById(R.id.txtPassword);
String email= epostaTxt.getText().toString();
String password = parolaTxt.getText().toString();
Sending emain and password to the server etc...
}
这只是暂时的,但此代码重复将继续。我想从Edittxt中获取此电子邮件和密码一次,并使用所有方法。而且这段代码也不起作用,Maillist没有显示列表,因为无法连接
我该怎么做?
答案 0 :(得分:0)
如果我很好地解读它,你只想在你的活动之间传递数据,这可能会有所帮助:In Android: How do I get variables/data from one screen to another?
编辑:我的新答案,希望它是好的: 只需创建两个变量来存储日期?public class LoginScreen extends Activity{
private String email;
private String password;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
LoginScreen();
}
// I am receiving the email and password on the main layout for login page
public void LoginScreen()
{
setContentView(R.layout.main);
EditText emailTxt = (EditText) findViewById(R.id.txtMail);
EditText passwordTxt = (EditText) findViewById(R.id.txtPassword);
email= emailTxt.getText().toString();
password = passwordTxt.getText().toString();
// After receive, call the MailList() for connection and getting the list
MailList()
}
// and I use this email and password again into the MailList() for connection with server then receive the mail list
public void MailList()
{
setContentView(R.layout.list);
//Sending emain and password to the server etc...
//just use the email and password stored above
yourFunctionToSend(email,password);
}
}