How to save state of onClickListener?

余生长醉 提交于 2019-12-02 06:27:22

Use sharedpreference to achieve this. store the button name and its value whenever you click on any button.

example

SharedPreferences pref = getSharedPreferences(PREFS_NAME,MODE_PRIVATE);   

        passwordInString = password.getText().toString();
        userNameInString = username.getText().toString();

        getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
        .edit()
        .putString(PREFS_USERNAME, passwordInString)
        .putString(PREFS_PASSWORD, userNameInString)
        .commit();

and in oncreate() always get the state of button using the following code Sample example

String usernameName = pref.getString(PREFS_USERNAME, "");
    String upassWord = pref.getString(PREFS_PASSWORD, "");

depending on the value you can set the state of button

You could use SharedPreferences for that purpose.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!