[英]How Can I Open Another Activity based on The Username and Password I Retrieve from MySQL using PHP?
[英]How can i change activity using login (username and password) ,button ?
我在 android 中創建了一個登錄頁面(使用 2 個 EditText 和一個按鈕)並保存一些本地定義的用戶名和密碼。
在執行期間,當用戶輸入正確的數據時,它會將其活動更改為下一個界面,我可以在其中將項目保留在 listmenu 上。
請幫忙。
使用一個類
public class myDataStore{
public static String uid;
public static String pwd;
}
其他選項是使用 Android 的應用程序類。 你的問題不清楚,你到底想做什么。
我從您的問題中了解到您想切換活動。
要更改當前活動並啟動另一個活動,您需要一個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);
}
}
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 設置為嘗試登錄,並且不要使用 == 來檢查字符串是否匹配使用方法 .matches()。 希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.