首页 新闻 赞助 找找看

eclipse开发安卓登录

0
悬赏园豆:20 [待解决问题]

划线的地方怎么解决啊?有没有大佬知道如何修改

package com.example.login;

import android.app.Activity;
import android.content.Context;
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.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {

private EditText userName, password;
private CheckBox rem_pw;
private Button btn_login;
private String userNameValue,passwordValue;
private SharedPreferences sp;

public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	//去除标题
	this.requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.activity_login);
	
    //获得实例对象
	sp = this.getSharedPreferences("userInfo", Context.MODE_PRIVATE);
	userName = (EditText)findViewById(R.id.et_zh);
	password = (EditText)findViewById(R.id.et_psd);
    rem_pw = (CheckBox)findViewById(R.id.cb_psd);
    btn_login = (Button)findViewById(R.id.btn_login);

	        
	//判断记住密码多选框的状态
  if(sp.getBoolean("ISCHECK", false))
    {
	  //设置默认是记录密码状态
      rem_pw.setChecked(true);
   	  userName.setText(sp.getString("USER_NAME", ""));
   	  password.setText(sp.getString("PASSWORD", ""));
    }
	
    // 登录监听事件  现在默认为用户名为:fang 密码:123
	btn_login.setOnClickListener(new OnClickListener() {

		public void onClick(View v) {
			userNameValue = userName.getText().toString();
		    passwordValue = password.getText().toString();
		    
			if(userNameValue.equals("fang")&&passwordValue.equals("123")){
				//跳转界面
				Bundle bundle = new Bundle();
				bundle.putString("name", userNameValue);
				bundle.putString("psd", passwordValue);
				Intent intent = new Intent(WelcomeActivity.this,WelcomeActivity.class);
				intent.putExtras(bundle);
				startActivity(intent);
				//finish();
				//登录成功和记住密码框为选中状态才保存用户信息
				if(rem_pw.isChecked())
				{
				 //记住用户名、密码、
				  Editor editor = sp.edit();
				  editor.putString("USER_NAME", userNameValue);
				  editor.putString("PASSWORD",passwordValue);
				  editor.commit();
				}

				
			}else{
				
				Toast.makeText(LoginActivity.this,"用户名或密码错误,请重新登录", Toast.LENGTH_LONG).show();
			}
			
		}
	});

    //监听记住密码多选框按钮事件
	rem_pw.setOnCheckedChangeListener(new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
			if (rem_pw.isChecked()) {
                
				System.out.println("记住密码已选中");
				sp.edit().putBoolean("ISCHECK", true).commit();
				
			}else {
				
				System.out.println("记住密码没有选中");
				sp.edit().putBoolean("ISCHECK", false).commit();
				
			}

		}
	});
}

}

问题补充:

图片波浪线的位置,百度了一下说是静态问题,看的一脸懵

拙劣前行者的主页 拙劣前行者 | 初学一级 | 园豆:182
提问于:2020-04-11 23:52

你的WelcomeActivity怎么声明的呢,是个内部类吧。 WelcomeActivity.this 改成 this 应该就可以了。可以看下enclosing class的定义。

。淑女范erり 3年前
< >
分享
所有回答(1)
0

你得贴上WelcomeActivity才能知道问题呀,调用出问题了就回调用的这个对象找问题。

西红柿里没有番茄 | 园豆:645 (小虾三级) | 2020-04-13 13:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册