1
可能重复:
ListView selection remains persistent after exiting choice modeListView项的DE /选择编程
我在我的应用程序列表视图,它包含了listitem_row.xml(布局我使用内部的多个组件每一个项目)。我面临的问题是我有一个ActionMode来选择每个项目。当用户选择任何项目时,动作模式被创建并按预期工作。当我关闭动作模式时,我想让项目看起来没有被选中/突出显示/激活/再次选中,因为它在选择之前。这里是我正在使用的代码:
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();
}
对于信息的缘故:我尝试了所有的组合单独和完全。我上面粘贴的代码是我没有看到任何工作时所达到的状态。我使用调试来检查所有状态,当用户点击关闭操作模式按钮时,处于真实状态的唯一状态是激活状态。
这是我为ListView行XML:
<?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>
任何建议/反馈将得到高度赞赏。
感谢Tobias它真的是..我应该关闭这个问题或什么?因为我是一个新用户,所以忍受着我... –