3

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 .

4

3 回答 3

1

使用一个类

public class myDataStore{

public static String uid;
public static String pwd; 
}

其他选项是使用 Android 的应用程序类。你的问题不清楚,你到底想做什么。

于 2013-08-02T14:18:17.267 回答
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);
    }
}
于 2013-08-02T14:41:16.913 回答
1
  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()。希望这可以帮助!

于 2013-08-02T18:04:48.720 回答