I created a log in page ( using 2 EditText and one button ) in android and save some local defined username and password .
During execution when user enters the correct data then it changes its activity to next interface where i can keep items on listmenu .
Please help .
use a class like
public class myDataStore{
public static String uid;
public static String pwd;
}
and other option is using Application Class of Android. Your question is not clear, What exactly you want to do.
What i understood from your question is that you want to switch activities.
To change the current activity and start another one you need an Intent
, that's called once you click on the submit button
.
First, you need to set your button OnClick
attribute to submit
for exemple,
<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" />
Then add a submit
method to your log 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);
}
}
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
}
}
Set your onclick to attemptLogin, and do not use == to check if a string matches use the method .matches(). Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.