I have implemented a list, using EnhancedListView, that allows users to remove items from it by swiping. But also I would like to allow users to select one item from the list by clicking on it.
For some reason when the I enable swipeToDismiss on the list and click on a item, all other items in the list get redrawn except the one I clicked. For this reason the clicked item view is not updated and never changes to the selected state.
You can see this my modifying the EnhancedListViewDemo application so it prints the list items that are redrawn in the getView() method and call the notifyDataSetChanged() on the adapter in the onItemClick callback.
When swipeToDismiss is disabled and you click on an item the notifyDataSetChanged() is called and you can see in the log that all items in the list are redrawn by calls to the getView() method.
When I enable the swipeToDismiss on the list and you click on an item you will notice on the logs that all items are redrawn (via getView()) except for the item you clicked.
You may use this patch to see what I am saying:
From c60e5b95add865fd3f5ba3efa2ee86fefbaf1ce1 Mon Sep 17 00:00:00 2001
From: Horacio Sanson <horacio@skillupjapan.co.jp>
Date: Mon, 30 Sep 2013 20:23:33 +0900
Subject: [PATCH] Simple test for testing a bug.
---
.../src/main/java/de/timroes/android/listviewdemo/MainActivity.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/EnhancedListViewDemo/src/main/java/de/timroes/android/listviewdemo/MainActivity.java b/EnhancedListViewDemo/src/main/java/de/timroes/android/listviewdemo/MainActivity.java
index 03268ce..b29d884 100644
--- a/EnhancedListViewDemo/src/main/java/de/timroes/android/listviewdemo/MainActivity.java
+++ b/EnhancedListViewDemo/src/main/java/de/timroes/android/listviewdemo/MainActivity.java
@@ -140,6 +140,7 @@ public class MainActivity extends ActionBarActivity {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Clicked on item " + mAdapter.getItem(position), Toast.LENGTH_SHORT).show();
+ mAdapter.notifyDataSetChanged();
}
});
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@@ -368,6 +369,7 @@ public class MainActivity extends ActionBarActivity {
}
holder.position = position;
+ Log.d("XXX", "Get view " + mItems.get(position));
holder.mTextView.setText(mItems.get(position));
return convertView;
--
1.8.1.2
I have implemented a list, using EnhancedListView, that allows users to remove items from it by swiping. But also I would like to allow users to select one item from the list by clicking on it.
For some reason when the I enable swipeToDismiss on the list and click on a item, all other items in the list get redrawn except the one I clicked. For this reason the clicked item view is not updated and never changes to the selected state.
You can see this my modifying the EnhancedListViewDemo application so it prints the list items that are redrawn in the getView() method and call the notifyDataSetChanged() on the adapter in the onItemClick callback.
When swipeToDismiss is disabled and you click on an item the notifyDataSetChanged() is called and you can see in the log that all items in the list are redrawn by calls to the getView() method.
When I enable the swipeToDismiss on the list and you click on an item you will notice on the logs that all items are redrawn (via getView()) except for the item you clicked.
You may use this patch to see what I am saying: