{"action":"closed","issue":{"url":"https://api.github.com/repos/JakeWharton/butterknife/issues/238","labels_url":"https://api.github.com/repos/JakeWharton/butterknife/issues/238/labels{/name}","comments_url":"https://api.github.com/repos/JakeWharton/butterknife/issues/238/comments","events_url":"https://api.github.com/repos/JakeWharton/butterknife/issues/238/events","html_url":"https://github.com/JakeWharton/butterknife/issues/238","id":60423471,"number":238,"title":"Preference injection?","user":{"login":"hzsweers","id":1361086,"avatar_url":"https://avatars.githubusercontent.com/u/1361086?v=3","gravatar_id":"","url":"https://api.github.com/users/hzsweers","html_url":"https://github.com/hzsweers","followers_url":"https://api.github.com/users/hzsweers/followers","following_url":"https://api.github.com/users/hzsweers/following{/other_user}","gists_url":"https://api.github.com/users/hzsweers/gists{/gist_id}","starred_url":"https://api.github.com/users/hzsweers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hzsweers/subscriptions","organizations_url":"https://api.github.com/users/hzsweers/orgs","repos_url":"https://api.github.com/users/hzsweers/repos","events_url":"https://api.github.com/users/hzsweers/events{/privacy}","received_events_url":"https://api.github.com/users/hzsweers/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-09T22:48:05Z","updated_at":"2015-03-09T23:41:36Z","closed_at":"2015-03-09T23:41:36Z","body":"This was an idea I had, but not really sure it's significant enough to warrant its own project and wanted to see if you'd be open to a pull request for it. It's not strictly view injection (preferences are mutants), but I feel like it could fall under the sort of swiss army knife of utilities that Butterknife offers.\r\n\r\nOften times when dealing with shared preferences, I end up with a case like this.\r\n\r\n```java\r\npublic class MyPreferenceFragment extends PreferenceFragment {\r\n\r\n    CheckboxPreference someCheckbox;\r\n\r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n\r\n        someCheckbox = (CheckboxPreference) findPreference(\"key_some_checkbox\");    \r\n        someCheckbox.setOnPreferenceChangeListener(new OnPreferenceChangeListener {\r\n            @Override\r\n            public boolean onPreferenceChange(Preference preference, Object newValue) {\r\n                // Do something\r\n                // Return something\r\n            }\r\n        }\r\n    }\r\n\r\n}\r\n```\r\n\r\nIt would be very nice to do something like this instead:\r\n\r\n```java\r\npublic class MyPreferenceFragment extends PreferenceFragment {\r\n\r\n    @InjectPreference(\"key_some_checkbox\")\r\n    CheckboxPreference someCheckbox;\r\n\r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n    }\r\n\r\n    @OnPreferenceChange(\"key_some_checkbox\")\r\n    boolean checkboxChanged(Preference preference, Object newValue) {\r\n        // Do something\r\n        // Return something\r\n    }\r\n\r\n}\r\n```\r\n\r\nThere's also `OnPreferenceClickListener`, binding multiple keys to a listener, and easy casting of the newValue's type as other pros. It's admittedly a niche use-case, but I think it would be a useful tool."}}