From 356e34d82427475dd15bac740557ba6ee24591a2 Mon Sep 17 00:00:00 2001 From: LeeReindeer Date: Fri, 30 Mar 2018 20:16:34 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20Fix=20IllegalStateException=20in=20samp?= =?UTF-8?q?le=20app.=20=E2=80=9CThe=20content=20of=20the=20adapter=20has?= =?UTF-8?q?=20changed=20but=20ListView=20did=20not=20receive=20a=20notific?= =?UTF-8?q?ation=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/xyz/leezoom/tree2/activity/MainActivity.kt | 6 ++++-- .../src/main/java/xyz/leezoom/view/treeview/TreeView.java | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/xyz/leezoom/tree2/activity/MainActivity.kt b/app/src/main/java/xyz/leezoom/tree2/activity/MainActivity.kt index 4fc6f31..d24b2b7 100644 --- a/app/src/main/java/xyz/leezoom/tree2/activity/MainActivity.kt +++ b/app/src/main/java/xyz/leezoom/tree2/activity/MainActivity.kt @@ -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 = nodes[position] as DefaultTreeNode @@ -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") diff --git a/treeview/src/main/java/xyz/leezoom/view/treeview/TreeView.java b/treeview/src/main/java/xyz/leezoom/view/treeview/TreeView.java index 86b57e3..f2bb2d7 100644 --- a/treeview/src/main/java/xyz/leezoom/view/treeview/TreeView.java +++ b/treeview/src/main/java/xyz/leezoom/view/treeview/TreeView.java @@ -63,7 +63,6 @@ public class TreeView extends ListView { private StringBuilder sb = new StringBuilder(); - // TODO: 12/14/17 use HashMap? private ArrayList searchList = new ArrayList<>(); //record the node's expanded status private HashMap expandedState;