Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Commit

Permalink
[Fix] Fix IllegalStateException in sample app.
Browse files Browse the repository at this point in the history
“The content of the adapter has changed but ListView did not receive a notification”
  • Loading branch information
LeeReindeer committed Mar 30, 2018
1 parent 84a44bf commit 356e34d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/xyz/leezoom/tree2/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ class MainActivity : AppCompatActivity() {
@Suppress("UNCHECKED_CAST")
private fun initView() {
initRoot()
tree_view.requestLayout()
adapter = FileTreeAdapter(this@MainActivity, root, R.layout.layout_file_tree_item)
tree_view.treeAdapter = adapter
tree_view.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
run {
Log.d(TAG, "Clicked pos: $position")
var nodes = adapter!!.nodesList
val nodes = adapter!!.nodesList
//for (i in 0 until nodes.size) Log.i(TAG, "index: $i,node:" + (nodes[i].element as FileItem).name)
//the click item
val node: DefaultTreeNode<FileItem> = nodes[position] as DefaultTreeNode<FileItem>
Expand Down Expand Up @@ -146,7 +147,8 @@ class MainActivity : AppCompatActivity() {
Log.d(TAG,"TreeView children: ${tree_view.childCount}")
//update view
adapter!!.nodesList = TreeUtils.getVisibleNodesD(root)
tree_view.refresh(null)
//tree_view.refresh(null)
adapter!!.notifyDataSetChanged()
//start animation
val offset = parent.firstVisiblePosition
Log.d(TAG, "anim offset: $offset")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class TreeView extends ListView {

private StringBuilder sb = new StringBuilder();

// TODO: 12/14/17 use HashMap?
private ArrayList<DefaultTreeNode> searchList = new ArrayList<>();
//record the node's expanded status
private HashMap<DefaultTreeNode, Boolean> expandedState;
Expand Down

0 comments on commit 356e34d

Please sign in to comment.