怎么始终不能跳转到另一个界面

YXTS122 2018-09-03 03:15:23
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();
}

}
}



}

...全文
1371 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
YXTS122 2018-09-09
  • 打赏
  • 举报
回复
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();
}


}



}

改成这样就可以跳转了
追风筝的孩子 2018-09-09
  • 打赏
  • 举报
回复
TextView denglu,没有设置点击事件啊。。。。
Warkerr 2018-09-07
  • 打赏
  • 举报
回复
试下不加判断是否能正常跳转,排除由判断引起;清单文件中是否注册了跳转的activity
r00_a2lBUR 2018-09-06
  • 打赏
  • 举报
回复
简单的跳转页面我的资源那里有
verejava 2018-09-05
  • 打赏
  • 举报
回复
Android 之 Activity Intent跳转和Bundle传值

http://www.verejava.com/?id=17458213555026
z523714705 2018-09-05
  • 打赏
  • 举报
回复
这种问题,自己断点下就知道了,你问出来,跳转代码没问题,逻辑就没办法看了
Write_BUG小能手 初级 2018-09-04
  • 打赏
  • 举报
回复
还有 自动登录 不应该是在闪屏页判断 是否登录过吗
Write_BUG小能手 初级 2018-09-04
  • 打赏
  • 举报
回复
你的判断有问题
YXTS122 2018-09-03
  • 打赏
  • 举报
回复
<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>

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧