Android自定義ListView無(wú)法單擊項(xiàng)目所以我有一個(gè)自定義的ListView對(duì)象。列表項(xiàng)目有兩個(gè)堆疊在一起的文本視圖,加上一個(gè)水平進(jìn)度條,我想保持隱藏,直到我實(shí)際執(zhí)行某些操作。最右邊是一個(gè)復(fù)選框,我只想在用戶需要將更新下載到他們的數(shù)據(jù)庫(kù)時(shí)顯示。當(dāng)我通過(guò)將可見性設(shè)置為Visibility.GONE來(lái)禁用復(fù)選框時(shí),我可以單擊列表項(xiàng)。當(dāng)復(fù)選框可見時(shí),除了復(fù)選框之外,我無(wú)法單擊列表中的任何內(nèi)容。我做了一些搜索,但沒有找到任何與我目前的情況相關(guān)的東西。我發(fā)現(xiàn)了這個(gè)問(wèn)題但我正在使用重寫的ArrayAdapter,因?yàn)槲艺谑褂肁rrayLists在內(nèi)部包含數(shù)據(jù)庫(kù)列表。我只需要獲取LinearLayout視圖并像Tom一樣添加onClickListener嗎?我不確定。這是listview行布局XML:<?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="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/UpdateNameText"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:textSize="18sp"
android:gravity="center_vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/UpdateStatusText"
android:singleLine="true"
android:ellipsize="marquee"
/>
3 回答

萬(wàn)千封印
TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
問(wèn)題是Android不允許您選擇具有可聚焦元素的列表項(xiàng)。我修改了列表項(xiàng)上的復(fù)選框,使其具有如下屬性:
android:focusable="false"
現(xiàn)在我的包含復(fù)選框的列表項(xiàng)(也適用于按鈕)在傳統(tǒng)意義上是“可選擇的”(它們點(diǎn)亮,您可以單擊列表項(xiàng)中的任何位置,“onListItemClick”處理程序?qū)⒂|發(fā)等)。
編輯:作為更新,一位評(píng)論者提到“只是一個(gè)注釋,在更改按鈕的可見性后,我必須以編程方式再次禁用焦點(diǎn)?!?/p>

千萬(wàn)里不及你
TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊
如果您在列表項(xiàng)中包含ImageButton,則應(yīng)將descendantFocusability
值設(shè)置為根列表項(xiàng)元素中的“blocksDescendants”。
android:descendantFocusability="blocksDescendants"
并在視圖中的focusableInTouchMode
標(biāo)志。true
ImageButton
android:focusableInTouchMode="true"
添加回答
舉報(bào)
0/150
提交
取消