我在android中创建了一个登录页面(使用2个EditText和一个按钮)并保存了一些本地定义的用户名和密码。
在执行期间,当用户输入正确的数据时,它会将其活动更改为下一个界面,我可以在列表菜单上保留项目。
请帮忙。
答案 0 :(得分:1)
使用类似
的类public class myDataStore{
public static String uid;
public static String pwd;
}
和其他选项是使用Android的Application Class。你的问题不明确, 你究竟想做什么。
答案 1 :(得分:1)
我从您的问题中了解到您想要切换活动。
要更改当前活动并启动另一项活动,您需要Intent
,点击提交button
后即可调用该活动。
首先,您需要将按钮OnClick
属性设置为submit
例如
<EditText
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="submit"
android:text="Button" />
然后在日志submit
中添加activity
方法:
public void submit(View view)
{
//here you put a condition to check if your login and password are correct
//You can for exemple compare them with values that you have in an sqlite database
if(myLogin.equals("correctLogin") && myPassword.equals("correctPassword"))
{
Intent intent = new Intent(yourLogActivity.this, yourListMenuActivity.class);
startActivity(intent);
}
}
答案 2 :(得分:0)
String userName = "Coolman"
String password = "IamTheKing"
public void attemptLogin(View view)
{
// Get the text from the editText that the user put in
String enteredUserName = ((EditText)findViewById(R.id.userNameText)).getText().toString();
String enteredPassword = ((EditText)findViewById(R.id.passwordText)).getText().toString();
// This will check to see if their login info matches
if(userName.matches(enteredUserName) && password.matches(enteredPassword))
{
Intent intent = new Intent(this, yourListMenuActivity.class);
startActivity(intent);
// and do what ever else you want to do here
}
}
将您的onclick设置为attemptLogin,并且不要使用==来检查字符串是否匹配使用方法.matches()。希望这有帮助!