到目前为止,我所做的是具有普通文本和可点击跨度的文本视图的列表视图:
单击我打开 URL 的跨度,单击 textView 周围的项目 View 会导致 listViewOnItemClickListener
导航到项目详细信息,这很好:
现在的问题是:
触摸 textView 会使普通文本有点突出显示(与完全选择项目时的颜色相同), textView 的OnTouchListener
触摸事件会触发但不会触发OnFocusChangeListener
事件,并且项目的 View 不会获得选择样式。尝试了FOCUS_BLOCK_DESCENDANTS
listView、item View 的所有变体,focusable
启用或禁用了 textView,结果相同。
幸运的是,textViewOnClickListener
事件以这种方式触发,但这太难看了:文本是不可见的,而触摸没有释放,因为选定的文本颜色与项目颜色相同,没有其他迹象表明用户将转到项目详细信息其他比那个丑陋的文字消失。
我怀疑发生这种情况是因为 textView 的内容是Spannable
,并且不是 CliclableSpan-s 的部分以这种奇怪的方式表现。
一旦触摸普通文本,我有机会选择该项目吗?
listView 项目布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:focusable="false" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:focusable="false"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:focusable="false"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:focusable="false"
android:gravity="fill_horizontal|right"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
</LinearLayout>
使用文本视图 setClickable(false) 我可以禁用这种奇怪的选择样式,在触摸文本视图区域时不会发生任何事情,虽然不好但可能对解决方案有用。
还尝试为每个项目添加不可聚焦和不可点击的按钮,当它被触摸时,整个项目被选中,当触摸被释放时,项目的点击事件被传递,这正是我对带有 Spannable 内容的 textView 所期望的。