{"action":"created","issue":{"url":"https://api.github.com/repos/davideas/FlexibleAdapter/issues/69","repository_url":"https://api.github.com/repos/davideas/FlexibleAdapter","labels_url":"https://api.github.com/repos/davideas/FlexibleAdapter/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/davideas/FlexibleAdapter/issues/69/comments","events_url":"https://api.github.com/repos/davideas/FlexibleAdapter/issues/69/events","html_url":"https://github.com/davideas/FlexibleAdapter/issues/69","id":148813268,"number":69,"title":"How to change the status of header item when it expand or collapse?","user":{"login":"hayukleung","id":4317481,"avatar_url":"https://avatars.githubusercontent.com/u/4317481?v=3","gravatar_id":"","url":"https://api.github.com/users/hayukleung","html_url":"https://github.com/hayukleung","followers_url":"https://api.github.com/users/hayukleung/followers","following_url":"https://api.github.com/users/hayukleung/following{/other_user}","gists_url":"https://api.github.com/users/hayukleung/gists{/gist_id}","starred_url":"https://api.github.com/users/hayukleung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hayukleung/subscriptions","organizations_url":"https://api.github.com/users/hayukleung/orgs","repos_url":"https://api.github.com/users/hayukleung/repos","events_url":"https://api.github.com/users/hayukleung/events{/privacy}","received_events_url":"https://api.github.com/users/hayukleung/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-16T03:48:22Z","updated_at":"2016-04-16T06:44:13Z","closed_at":"2016-04-16T03:56:36Z","body":"I try to change the status of header item when it expand or collapse:\r\n\r\n\r\n`eu.davidea.examples.models.ExpandableHeaderItem.java`\r\n\r\n`@Override`\r\n`public void bindViewHolder(FlexibleAdapter adapter, ExpandableHeaderViewHolder holder, int position, List payloads) {`\r\n`    if (payloads.size() > 0) {`\r\n`        Log.i(this.getClass().getSimpleName(), \"ExpandableHeaderItem Payload \" + payloads);`\r\n`    } else {`\r\n`        holder.mTitle.setText(getTitle());`\r\n`    }`\r\n`    setSubtitle(adapter.getCurrentChildren(this).size() + \" subItems\");`\r\n`    holder.mSubtitle.setText(getSubtitle());`\r\n`    // my code -------------------------------------------------------------------------------------`\r\n`    if (isExpanded()) {`\r\n`        holder.mSubtitle.setText(\"expanded\");`\r\n`    } else {`\r\n`        holder.mSubtitle.setText(\"collapse\");`\r\n`    }`\r\n`    // my code --------------------------------------------------------------------------------------`\r\n`}`\r\n\r\nthank you!"},"comment":{"url":"https://api.github.com/repos/davideas/FlexibleAdapter/issues/comments/210748052","html_url":"https://github.com/davideas/FlexibleAdapter/issues/69#issuecomment-210748052","issue_url":"https://api.github.com/repos/davideas/FlexibleAdapter/issues/69","id":210748052,"user":{"login":"davideas","id":12213847,"avatar_url":"https://avatars.githubusercontent.com/u/12213847?v=3","gravatar_id":"","url":"https://api.github.com/users/davideas","html_url":"https://github.com/davideas","followers_url":"https://api.github.com/users/davideas/followers","following_url":"https://api.github.com/users/davideas/following{/other_user}","gists_url":"https://api.github.com/users/davideas/gists{/gist_id}","starred_url":"https://api.github.com/users/davideas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davideas/subscriptions","organizations_url":"https://api.github.com/users/davideas/orgs","repos_url":"https://api.github.com/users/davideas/repos","events_url":"https://api.github.com/users/davideas/events{/privacy}","received_events_url":"https://api.github.com/users/davideas/received_events","type":"User","site_admin":false},"created_at":"2016-04-16T06:44:13Z","updated_at":"2016-04-16T06:44:13Z","body":"@hayukleung, yes it works but I give you the correct lines and command. if you use `notifyDataSetChanged()` you are going to bind again **all** items! And `onClick()` is not at all the good place to add it, because the `expand()` and `collapse()` methods are called under some conditions, override the 2 methods like this in `ExpandableHeaderViewHolder`:\r\n\r\n``` java\r\n@Override\r\nprotected void expandView(int position) {\r\n\tsuper.expandView(position);\r\n\t//Let's notify the item has been expanded\r\n\tif (mAdapter.isExpanded(position)) mAdapter.notifyItemChanged(position, true);\r\n}\r\n\r\n@Override\r\nprotected void collapseView(int position) {\r\n\tsuper.collapseView(position);\r\n\t//Let's notify the item has been collapsed\r\n\tif (!mAdapter.isExpanded(position)) mAdapter.notifyItemChanged(position, true);\r\n}\r\n```\r\n\r\nBasically you notify **only** that item and also you send a payload object that you will check in the bind method to even optimize the single view binding:\r\n\r\n``` java\r\n@Override\r\npublic void bindViewHolder(FlexibleAdapter adapter, ExpandableHeaderViewHolder holder, int position, List payloads) {\r\n\tif (payloads.size() > 0) {\r\n\t\tLog.i(this.getClass().getSimpleName(), \"ExpandableHeaderItem Payload \" + payloads);\r\n\t} else {\r\n\t\tholder.mTitle.setText(getTitle());\r\n\t}\r\n\tsetSubtitle(String.valueOf(adapter.getCurrentChildren(this).size()) +\r\n\t\t\t\" subItems (\" + (isExpanded() ? \"expanded\" : \"collapsed\") + \")\");\r\n\tholder.mSubtitle.setText(getSubtitle());\r\n}\r\n```\r\n\r\nI added this code to the example app. I will commit soon with many others changes for the demo app, keep watched my commits :-)"}}