qq_38795939 2017-11-16 12:36 采纳率: 0%
浏览 881

萌新关于跳转问题的问题!!!!!!

package com.example.application;

import actionmovie.LoginActivity;
import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.animation.AlphaAnimation;

import android.view.animation.Animation;

import android.view.animation.Animation.AnimationListener;

import android.widget.ImageView;

public class MainActivity extends Activity {

private ImageView welcomeImg = null;

@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.activity_main);  
    welcomeImg = (ImageView) this.findViewById(R.id.welcome_img);  
    AlphaAnimation anima = new AlphaAnimation(0.3f, 1.0f);  
    anima.setDuration(3000);// 设置动画显示时间  
    welcomeImg.startAnimation(anima);  
    anima.setAnimationListener(new AnimationImpl());  

}  

private class AnimationImpl implements AnimationListener {  

    @Override  
    public void onAnimationStart(Animation animation) {  
        welcomeImg.setBackgroundResource(R.drawable.boot_0000);  
    }  

    @Override  
    public void onAnimationEnd(Animation animation) {  
        skip(); // 动画结束后跳转到别的页面  
    }  

    @Override  
    public void onAnimationRepeat(Animation animation) {  

    }  

}  

private void skip() {  
    startActivity(new Intent(MainActivity.this, LoginActivity.class));  
    finish();  
}  

}

上述是开机动画,要跳到 LoginActivity,动画结束后失败。
package actionmovie;

import com.example.application.BMainActivity;
import com.example.application.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity implements OnClickListener {

private Button logbtn = null;
private EditText username = null;
private EditText password = null;
private String pswd, name;
private CheckBox checkboxButton = null;
SharedPreferences sp = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    init();
}

private void init() {
    // TODO Auto-generated method stub
    username = (EditText) findViewById(R.id.login_edit_account);
    password = (EditText) findViewById(R.id.login_edit_pwd);
    logbtn = (Button) findViewById(R.id.login_btn_login);
    checkboxButton = (CheckBox) findViewById(R.id.Login_Remember);

    if (sp.getBoolean("checkboxBoolean", false)) {
        username.setText(sp.getString("username", null));
        password.setText(sp.getString("password", null));
        checkboxButton.setChecked(true);

    }
    logbtn.setOnClickListener(LoginActivity.this);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    name = username.getText().toString().trim();
    pswd = password.getText().toString().trim();
    if (v == logbtn) {
        if (name.equals("admin") && pswd.equals("123456")) {
            if (name.trim().equals("")) {
                Toast.makeText(this, "请您输入用户名!", Toast.LENGTH_SHORT).show();
                return;
            }
            if (pswd.trim().equals("")) {
                Toast.makeText(this, "请您输入密码!", Toast.LENGTH_SHORT).show();
                return;
            }
            boolean CheckBoxLogin = checkboxButton.isChecked();
            if (CheckBoxLogin) {
                Editor editor = sp.edit();
                editor.putString("username", name);
                editor.putString("password", pswd);
                editor.putBoolean("checkboxBoolean", true);
                editor.commit();
            } else {
                Editor editor = sp.edit();
                editor.putString("user", null);
                editor.putString("pass", null);
                editor.putBoolean("checkboxBoolean", false);
                editor.commit();
            }
            Intent intent = new Intent();
            intent.setClass(LoginActivity.this, BMainActivity.class);
            startActivity(intent);
            finish();
        } else {
            AlertDialog.Builder builder = new Builder(LoginActivity.this);
            builder.setTitle("                                          请确认!");
            builder.setMessage("                                    账号或密码错误");
            builder.setPositiveButton("是", null);
            builder.show();
        }
    }
}

}
两段代码,我一段段的切掉运行,发现在
if (sp.getBoolean("checkboxBoolean", false)) {
username.setText(sp.getString("username", null));
password.setText(sp.getString("password", null));
checkboxButton.setChecked(true);

    }
    缺少这个if语句是不会停止运行,且跳转成功,请问怎么解决啊。
  • 写回答

1条回答 默认 最新

  • qq_38795939 2017-11-16 13:36
    关注

    大佬们求解答啊啊啊啊

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题