Java android中服务器验证的共享首选项概念登录页面

Java android中服务器验证的共享首选项概念登录页面,java,android,Java,Android,我确认登录页面由服务器端完成。我为记住用户名和密码创建了一个复选框。如果选中该复选框,它会记住用户名和密码。但问题是,即使未选中该复选框,它也会找到存储的用户名和密码。现在我想知道,如果复选框未选中,意味着它不能记住用户名和密码 i try this code public class Login extends Activity { SharedPreferences app_preferences ; CheckBox check; private static final

我确认登录页面由服务器端完成。我为记住用户名和密码创建了一个复选框。如果选中该复选框,它会记住用户名和密码。但问题是,即使未选中该复选框,它也会找到存储的用户名和密码。现在我想知道,如果复选框未选中,意味着它不能记住用户名和密码

 i try this code
   public class Login extends Activity {
  SharedPreferences app_preferences ;
CheckBox check;


private static final String UPDATE_URL = "serverurl";

public ProgressDialog progressDialog;

private EditText UserEditText;

private EditText PassEditText;



public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);


    app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
    progressDialog = new ProgressDialog(this);

    progressDialog.setMessage("Please wait...");

    progressDialog.setIndeterminate(true);

    progressDialog.setCancelable(false);



    UserEditText = (EditText) findViewById(R.id.username);

    PassEditText = (EditText) findViewById(R.id.password);
    check=(CheckBox) findViewById(R.id.checkbox);
    String Str_user = app_preferences.getString("username","0" );
    String Str_pass = app_preferences.getString("password", "0");
    String Str_check = app_preferences.getString("checked", "no");
    if(Str_check.equals("yes"))
    {
            UserEditText.setText(Str_user);
           PassEditText.setText(Str_pass);
            check.setChecked(true);
    }
    Button button = (Button) findViewById(R.id.okbutton);

    button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            int usersize = UserEditText.getText().length();

            int passsize = PassEditText.getText().length();

            if(usersize > 0 && passsize > 0) {

                progressDialog.show();

                String user = UserEditText.getText().toString();

                String pass = PassEditText.getText().toString();
                String Str_check2 = app_preferences.getString("checked", "no");
                if(Str_check2.equals("yes"))
                {
                    SharedPreferences.Editor editor = app_preferences.edit();
                    editor.putString("username", user);
                    editor.putString("password", pass);
                     editor.commit();
                }

                doLogin(user, pass);

            } else createDialog("Error","Please enter Username and Password");

        }

    });

   check box
    check.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                // Perform action on clicks, depending on whether it's now checked
                SharedPreferences.Editor editor = app_preferences.edit();
                if (((CheckBox) v).isChecked())
                {

                     editor.putString("checked", "yes");
                     editor.commit();
                }
                else
                {
                     editor.putString("checked", "no");
                     editor.commit();
                }
            }
        });
试一试


当用户取消选中复选框时,您应删除存储的详细信息。在这里,即使用户取消选中复选框,您仍保留存储的值

 check box
        check.setOnClickListener(new View.OnClickListener()
            {
                public void onClick(View v)
                {
                    // Perform action on clicks, depending on whether it's now checked
                    SharedPreferences.Editor editor = app_preferences.edit();
                    if (((CheckBox) v).isChecked())
                    {

editor.putString("username", user);
                    editor.putString("password", pass);
                         editor.putString("checked", "yes");
                         editor.commit();
                    }
                    else
                    {

editor.putString("username", "");
                    editor.putString("password", "");
editor.putString("checked", "no");
                         editor.commit();
                    }
                }
            });

我试试看,什么事都不会发生。我得到了相同的输出。若复选框被选中意味着它记住用户名和密码,否则它不记得用户名和密码password@Vinoth .. 那你想要什么…?我试过了,但我能得到同样的结果。我用这个链接尝试了我的登录页面。我添加了“记住”复选框。请查看如何在登录页面中实现“记住我”概念的链接。您会重复多少次相同的问题?&再次。。。。???
 check box
        check.setOnClickListener(new View.OnClickListener()
            {
                public void onClick(View v)
                {
                    // Perform action on clicks, depending on whether it's now checked
                    SharedPreferences.Editor editor = app_preferences.edit();
                    if (((CheckBox) v).isChecked())
                    {

editor.putString("username", user);
                    editor.putString("password", pass);
                         editor.putString("checked", "yes");
                         editor.commit();
                    }
                    else
                    {

editor.putString("username", "");
                    editor.putString("password", "");
editor.putString("checked", "no");
                         editor.commit();
                    }
                }
            });