From e65c953163f528f892ff010a38b90fa69b6352e1 Mon Sep 17 00:00:00 2001 From: Hendrik Borghorst Date: Tue, 17 Oct 2017 22:40:49 +0200 Subject: [PATCH] Fix ui freeze when changing output profile by reusing view --- .../malp/application/adapters/OutputAdapter.java | 10 ++++++++-- .../malp/application/listviewitems/OutputListItem.java | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/gateshipone/malp/application/adapters/OutputAdapter.java b/app/src/main/java/org/gateshipone/malp/application/adapters/OutputAdapter.java index f6a968aa..b02cac6c 100644 --- a/app/src/main/java/org/gateshipone/malp/application/adapters/OutputAdapter.java +++ b/app/src/main/java/org/gateshipone/malp/application/adapters/OutputAdapter.java @@ -49,8 +49,14 @@ public View getView(int position, View convertView, ViewGroup parent) { int outputId = output.getID(); boolean active = output.getOutputState(); - - convertView = new OutputListItem(mContext, outputName, active, outputId); + if ( convertView == null ) { + // Create a new View and not reuse it + convertView = new OutputListItem(mContext, outputName, active, outputId); + } else { + OutputListItem outputItem = (OutputListItem)convertView; + outputItem.setName(outputName); + outputItem.setChecked(active); + } return convertView; } diff --git a/app/src/main/java/org/gateshipone/malp/application/listviewitems/OutputListItem.java b/app/src/main/java/org/gateshipone/malp/application/listviewitems/OutputListItem.java index 96d42943..81b21fa3 100644 --- a/app/src/main/java/org/gateshipone/malp/application/listviewitems/OutputListItem.java +++ b/app/src/main/java/org/gateshipone/malp/application/listviewitems/OutputListItem.java @@ -47,4 +47,12 @@ public OutputListItem(Context context, String outputName, boolean active, int ou mMainView.setChecked(active); } + public void setName(String name) { + mMainView.setText(name); + } + + public void setChecked(boolean checked) { + mMainView.setChecked(checked); + } + }