English 中文(简体)
共享的优惠概念标志
原标题:shared preference concept login page from server validation in android
  • 时间:2012-04-20 04:41:30
  •  标签:
  • java
  • android

i 标识页由服务器方验证。 i 为记住用户名和密码建立一个核对箱。 如果核对箱子,就会记住用户名称和密码。 但是,即使检查箱没有检查,也发现用户名称和密码。 现在,如果检查箱没有受到检查,就不能记住用户名称和密码。

 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();
                }
            }
        });
最佳回答

审判

 String Str_check = app_preferences.getString("checked", "no");
    if(Str_check.equals("yes"))
    {
String Str_user = app_preferences.getString("username","0" );
    String Str_pass = app_preferences.getString("password", "0");

            UserEditText.setText(Str_user);
           PassEditText.setText(Str_pass);
            check.setChecked(true);
    }
else{
   SharedPreferences.Editor editor = app_preferences.edit();
                    editor.putString("username", "");
                    editor.putString("password", "");
                     editor.commit();
}
问题回答

当用户不核对检查箱时,请should删除储存的细节。 这里,您是---->----------------------------------------------------------------------------------------------------------------------------------------------------------------

 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();
                    }
                }
            });




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...