{"action":"closed","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/2006","labels_url":"https://api.github.com/repos/realm/realm-java/issues/2006/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/2006/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/2006/events","html_url":"https://github.com/realm/realm-java/issues/2006","id":123990813,"number":2006,"title":"Delete realm object with checkbox listener inside ListView","user":{"login":"csnu17","id":15520417,"avatar_url":"https://avatars.githubusercontent.com/u/15520417?v=3","gravatar_id":"","url":"https://api.github.com/users/csnu17","html_url":"https://github.com/csnu17","followers_url":"https://api.github.com/users/csnu17/followers","following_url":"https://api.github.com/users/csnu17/following{/other_user}","gists_url":"https://api.github.com/users/csnu17/gists{/gist_id}","starred_url":"https://api.github.com/users/csnu17/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csnu17/subscriptions","organizations_url":"https://api.github.com/users/csnu17/orgs","repos_url":"https://api.github.com/users/csnu17/repos","events_url":"https://api.github.com/users/csnu17/events{/privacy}","received_events_url":"https://api.github.com/users/csnu17/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/Help","name":"Help","color":"cc317c"},{"url":"https://api.github.com/repos/realm/realm-java/labels/Pending","name":"Pending","color":"ededed"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-27T18:15:49Z","updated_at":"2015-12-28T17:39:35Z","closed_at":"2015-12-28T17:39:35Z","body":"Im create ListView with OnItemLongClickListener that make selected object will be deleted. This is my code:\r\n\r\n``` java\r\nmRatioItemLv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {\r\n@Override\r\n            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long l) {\r\n                mRealm.beginTransaction();\r\n                results.remove(position);\r\n                mRealm.commitTransaction();\r\n                mRatioItemAdapter.updateList(results);\r\n                return true;\r\n            }\r\n});\r\n```\r\nAfter that the adapter call notifyDataSetChanged() (mRatioItemAdapter.updateList(results);) and this is my adapter's getView method:\r\n\r\n``` java\r\nfinal IncomingRatio item = (IncomingRatio) getItem(position);\r\n            viewHolder.ratioTitleTv.setText(item.getRatioTitle());\r\n            viewHolder.ratioItemCheckbox.setChecked(item.getActive());\r\n\r\n            viewHolder.ratioItemCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {\r\n                @Override\r\n                public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {\r\n                    Realm realm = Realm.getDefaultInstance();\r\n                    realm.beginTransaction();\r\n                    if (item.isValid()) item.setActive(isChecked);\r\n                    realm.commitTransaction();\r\n                    realm.close();\r\n                }\r\n            });\r\n```\r\nSenario: 5 dataSet\r\n1. row 0, checkbox state = 1\r\n    row 1, checkbox state = 1\r\n    row 2, checkbox state = 1\r\n    row 3, checkbox state = 1\r\n    row 4, checkbox state = 1\r\n\r\n2. Click checkbox on row 1, 2, 3. Now the state is:\r\n    row 0, checkbox state = 1\r\n    row 1, checkbox state = 0\r\n    row 2, checkbox state = 0\r\n    row 3, checkbox state = 0\r\n    row 4, checkbox state = 1\r\n\r\n3. Long press on ListView (Delete item) at row 2 and the expected result should be:\r\n    row 0, checkbox state = 1\r\n    row 1, checkbox state = 0\r\n    row 3, checkbox state = 0\r\n    row 4, checkbox state = 1\r\n\r\nbut when I use Realm browser look at my .realm file it shown\r\n    row 0, checkbox state = 1\r\n    row 1, checkbox state = 0\r\n    row 4, checkbox state = 1\r\n    row 3, checkbox state = 1\r\n    \r\nI think I know Realm deletion mechanism. If the deletion is called, it will move last row to replace deleted row. But I dont understand why the row 3, checkbox state is turn to 1. It should be 0. Maybe the index of RealmResults is wrong after delete object? If I remove .isValid() method, app will be crash. Thank you for your help and sorry for my English."}}