diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java index 1cafa80..56a39e3 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java @@ -216,23 +216,25 @@ public class ExplorerActivity extends AppCompatActivity { setTitle(filesDir.getName()); filePath.set(filesDir.getAbsolutePath()); fileHandler.post(() -> { - List> files = loadFiles(filesDir); + final List> files = loadFiles(filesDir); - listView.setAdapter(new SimpleAdapter( - this, - files, - android.R.layout.simple_list_item_1, - new String[]{"name"}, - new int[]{android.R.id.text1} - )); + runOnUiThread(() -> { + listView.setAdapter(new SimpleAdapter( + this, + files, + android.R.layout.simple_list_item_1, + new String[]{"name"}, + new int[]{android.R.id.text1} + )); - listView.setOnItemClickListener((parent, view, position, id) -> { - File clickedFile = (File) files.get(position).get("file"); - if (clickedFile.isFile()) { - handleFileClick(clickedFile); - } else if (clickedFile.isDirectory()) { - updateListView(clickedFile); - } + listView.setOnItemClickListener((parent, view, position, id) -> { + File clickedFile = (File) files.get(position).get("file"); + if (clickedFile.isFile()) { + handleFileClick(clickedFile); + } else if (clickedFile.isDirectory()) { + updateListView(clickedFile); + } + }); }); }); }