80,472
社区成员




public class MainActivity extends Activity {
String str_user,str_pass;
TextView denglu,zuce;
EditText user,pass;
CheckBox checkBox_zidongdenglu;
SharedPreferences sp;
SharedPreferences.Editor editor;
SharedPreferences sp_user;
SharedPreferences.Editor editor_user;
SharedPreferences sp_flag;
SharedPreferences.Editor editor_flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
user=(EditText) findViewById(R.id.user);
pass=(EditText) findViewById(R.id.pass);
denglu=(TextView) findViewById(R.id.denglu);
zuce=(TextView) findViewById(R.id.zuce);
checkBox_zidongdenglu=(CheckBox) findViewById(R.id.CheckBox_zidong);
sp=getSharedPreferences("zddl",MODE_PRIVATE);//自动登录
sp_user=getSharedPreferences("user",MODE_PRIVATE);//用户
sp_flag=getSharedPreferences("flag",MODE_PRIVATE);//用户信息完整判断flag
editor=sp.edit();
editor_user=sp_user.edit();
editor_flag=sp_flag.edit();
String flag=sp.getString("flag","0");
//自动登录
if(flag.equals("exist")){
if("flag".equals(sp_flag.getString("flag","0"))){
Intent i=new Intent(MainActivity.this,zhuActivity.class);
startActivity(i);
finish();
}
if(checkBox_zidongdenglu.isChecked()){
editor.putString("flag","exist");
editor.commit();
}
editor_user.putString("username",str_user);
editor_user.putString("password",str_pass);
editor_user.commit();
//判断用户信息是否填写完整 判断flag
if("flag".equals(sp_flag.getString("flag","0"))){
Intent i=new Intent(MainActivity.this,zhuActivity.class);
startActivity(i);
finish();
}
}
}
}
public class MainActivity extends Activity {
String str_user,str_pass;
TextView denglu,zuce;
EditText user,pass;
CheckBox checkBox_zidongdenglu;
SharedPreferences sp;
SharedPreferences.Editor editor;
SharedPreferences sp_user;
SharedPreferences.Editor editor_user;
SharedPreferences sp_flag;
SharedPreferences.Editor editor_flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
user=(EditText) findViewById(R.id.user);
pass=(EditText) findViewById(R.id.pass);
denglu=(TextView) findViewById(R.id.denglu);
zuce=(TextView) findViewById(R.id.zuce);
checkBox_zidongdenglu=(CheckBox) findViewById(R.id.CheckBox_zidong);
sp=getSharedPreferences("zddl",MODE_PRIVATE);//自动登录
sp_user=getSharedPreferences("user",MODE_PRIVATE);//用户
sp_flag=getSharedPreferences("flag",MODE_PRIVATE);//用户信息完整判断flag
editor=sp.edit();
editor_user=sp_user.edit();
editor_flag=sp_flag.edit();
String flag=sp.getString("flag","0");
//自动登录
str_user=user.getText().toString();
str_pass=pass.getText().toString();
editor_user.putString("username",str_user);
editor_user.putString("password",str_pass);
editor_user.commit();
if(checkBox_zidongdenglu.isChecked()){
editor.putString("flag","exist");
editor.commit();
}
if(flag.equals("exist")){
Intent i=new Intent(MainActivity.this,zhuActivity.class);
startActivity(i);
finish();
}
//判断用户信息是否填写完整 判断flag
if("flag".equals(sp_flag.getString("flag","0"))){
Intent i=new Intent(MainActivity.this,zhuActivity.class);
startActivity(i);
finish();
}
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.zto.MainActivity"
android:orientation="vertical" >
<LinearLayout
android:layout_marginTop="50dp"
android:layout_marginLeft="29dp"
android:layout_marginRight="29dp"
android:layout_marginBottom="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:layout_width="158dp"
android:layout_height="158dp" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="22dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="用户名"/>
<EditText
android:id="@+id/user"
android:layout_weight="3"
android:layout_width="0dp"
android:lines="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="22dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="密码"/>
<EditText
android:id="@+id/pass"
android:inputType="textPassword"
android:layout_weight="3"
android:layout_width="0dp"
android:lines="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginLeft="31dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/CheckBox_zidong"
android:text="自动登录"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="120dp"
android:layout_marginLeft="29dp"
android:layout_marginRight="29dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/denglu"
android:text="登陆"
android:textSize="35dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginLeft="29dp"
android:layout_marginRight="29dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/zuce"
android:text="注册新用户"
android:textColor="#4169E1"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_marginTop="75dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="22dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="用户名"/>
<EditText
android:id="@+id/zuce_user"
android:layout_weight="2"
android:layout_width="0dp"
android:maxLength="8"
android:hint="5至8位(字母、数字)"
android:lines="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="22dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="密码"/>
<EditText
android:id="@+id/zuce_pass"
android:maxLength="12"
android:layout_weight="2"
android:inputType="textPassword"
android:hint="8至12位"
android:layout_width="0dp"
android:lines="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="22dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="确认密码"/>
<EditText
android:id="@+id/zuce_againpass"
android:layout_width="0dp"
android:maxLength="12"
android:hint="重新输入密码"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:layout_weight="2"
android:lines="1" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="22dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="邀请码"/>
<EditText
android:id="@+id/zuce_yaoqingma"
android:layout_width="0dp"
android:hint="没有可不填"
android:layout_height="wrap_content"
android:layout_weight="2"
android:lines="1" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="75dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/zuce_zuce"
android:text="注册"
android:textSize="35dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>