我的工作有一个"每周给我上记录的在"国家对我的应用程序。我应该怎么办呢? [英] I'm working on having a "Keep me on Logged in" state on my app. How should i do it?

查看:80
本文介绍了我的工作有一个"每周给我上记录的在"国家对我的应用程序。我应该怎么办呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="horizontal"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="#FFFFFF">

    <TextView android:id="@+id/welcome_text"
        android:text = "Log-In"   
        android:textColor="#000000"        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="40dp"
        android:layout_centerHorizontal="true"/>
     <TextView
        android:id="@+id/username_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="20dip"
        android:layout_marginTop="100dip"
        android:layout_marginLeft="30dip"
        android:text="Username:"
        android:textColor="#000000"/>
    <EditText
        android:id="@+id/txt_username"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background"
        android:layout_toRightOf="@id/username_text"
        android:layout_alignTop="@id/username_text"/>
     <TextView
        android:id="@+id/password_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/username_text"
        android:layout_marginRight="20dip"
        android:layout_marginTop="30dip"
        android:layout_marginLeft="30dip"
        android:text="Password:"
        android:textColor="#000000"/>
    <EditText
        android:id="@+id/txt_password"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background"
        android:layout_toRightOf="@id/password_text"
        android:layout_alignTop="@id/password_text"
        android:layout_below="@id/txt_username"
        android:layout_marginLeft="5dip"
        android:password="true"        />
    <Button
        android:id="@+id/login_button"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txt_password"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="35dip"
        android:layout_marginLeft="110dip"
        android:text="Submit" />
     <TextView
        android:id="@+id/tv_error"
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:textSize="5pt"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/txt_password"
        android:layout_marginRight="9dip"
        android:layout_marginTop="9dip"
        android:layout_marginLeft="15dip"
        android:textColor="#FF0000"
        android:text=""/>
     <TextView android:id="@+id/tv_login"
        android:text = "@string/Login"   
        android:textColor="#000000"        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="40dp"
        android:layout_below="@id/login_button"
        android:layout_centerHorizontal="true"/>
     <RadioGroup
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/tv_login"
      android:orientation="horizontal"
      android:layout_centerHorizontal="true">
      <RadioButton android:id="@+id/on"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="9dip"
          android:text="On" 
          android:textColor="#000000"/>
      <RadioButton android:id="@+id/off"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="9dip"
          android:layout_marginLeft="20dip"
          android:text="Off" 
          android:textColor="#000000"/>
    </RadioGroup>
</RelativeLayout>

和这里是我的java:

and here's my java:

public class LogInActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loginactivity);

        final RadioButton radio_on = (RadioButton) findViewById(R.id.on);
        final RadioButton radio_off = (RadioButton) findViewById(R.id.off);

        Button launch = (Button)findViewById(R.id.login_button);
        launch.setOnClickListener(new OnClickListener()
        {
         public void onClick(View v) {
           EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
           EditText passwordEditText = (EditText) findViewById(R.id.txt_password);
           TextView loginTextView = (TextView)findViewById(R.id.tv_error);

           String sUserName = usernameEditText.getText().toString();
           String sPassword = passwordEditText.getText().toString();

            if(sUserName.equals("numlock") && sPassword.equals("numlock")) {
                Intent intent = new Intent(LogInActivity.this, HomeActivity.class);
                startActivity(intent);
            }
             else {
                loginTextView.setText("Login failed. Username and/or password doesn't match.");
                 }
            }
        }); 
    }
}

我要分配的让我登录的状态的单选按钮。任何帮助?

I want to assign the keep me logged in state on the radio buttons. Any help?

推荐答案

您可以通过使用做到这一点的共享preference 静态变量应用类,它会帮助你保持用户的状态

You can do it by using SharedPreference, Static variables or by Application class which will helps you in keeping the state of the User

这篇关于我的工作有一个&QUOT;每周给我上记录的在&QUOT;国家对我的应用程序。我应该怎么办呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆