1

Possible Duplicate:
ListView selection remains persistent after exiting choice mode

I have a listview in my application and it contains multiple components inside the listitem_row.xml(layout i am using for each item). The problem i am facing is that I have an ActionMode for the selection of each item. When user selects any item, the action mode gets created and works as expected. When i close the action mode, I want to make the item look not-selected/highlighted/activated/checked again as it was before selection. Here is the code i am using:

if (selectedView.isPressed()) {
    selectedView.setPressed(false);
}
if (selectedView.isActivated()) {
    selectedView.setActivated(false);
}
if (selectedView.isSelected()) {
    selectedView.setSelected(false);
}
if (selectedView.isFocused()) {
    selectedView.clearFocus();
    selectedView.dispatchWindowFocusChanged(false);
}
selectedView.refreshDrawableState();
selectedView.requestLayout();
if (selectedView.isDirty()) {
    selectedView.postInvalidate();
}

For the informations' sake: I tried all the combinations alone and altogether. The code i pasted above is the state which i reached when nothing seems to be working. I checked all the states using the debug and when user clicks on the close action mode button, the only state which is in true condition is activated state.

Here is my xml for the listview row:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/row"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:orientation="vertical" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/innerrow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/listview_selector"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/listViewHeading"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/mydrawable"
            android:drawablePadding="5sp"
            android:gravity="center|left"
            android:paddingBottom="5sp"
            android:paddingLeft="15sp"
            android:paddingRight="15sp"
            android:paddingTop="5sp"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/app_text_color"
            android:textStyle="bold" />

        <View
            style="@style/line"
            android:layout_width="match_parent"
            android:layout_height="1dp" />

        <TextView
            android:id="@+id/listViewDetail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="15sp"
            android:paddingLeft="15sp"
            android:paddingRight="15sp"
            android:paddingTop="5sp"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/app_text_color" />
    </LinearLayout>

</LinearLayout>

Any suggestion/feedback would be highly appreciated.

Community
  • 1
  • 1
Hammad Dar
  • 475
  • 8
  • 18

1 Answers1

0

For any ListView item, which already has a single choice mode for it, only two lines are required for the removal of the selection:

myListView.clearChoices();
myListView.requestLayout();

This solved my problem.

Hammad Dar
  • 475
  • 8
  • 18