導航:首頁 > 操作系統 > androidlistview設置焦點

androidlistview設置焦點

發布時間:2022-06-06 14:25:00

1. android開發 listview中textview搶焦點問題

如果你的自定義ListViewItem中有Button或者Checkable的子類控制項的話,那麼默認focus是交給了子控制項,而ListView的Item能被選中的基礎是它能獲取Focus。
我們可以通過對Item Layout的根控制項設置其android:descendantFocusability=」blocksDescendants」來解決,這樣Item Layout就屏蔽了所有子控制項獲取Focus的許可權,如此就可以順利的響應onItemClickListener中的onItenClick()方法了。

android:descendantFocusability有三種屬性:
beforeDescendants:viewgroup會優先其子類控制項而獲取到焦點
afterDescendants:viewgroup只有當其子類控制項不需要獲取焦點時才獲取焦點
blocksDescendants:viewgroup會覆蓋子類控制項而直接獲得焦點

2. 如何控制listview的焦點

1.將ListView的Item Layout的子控制項focusable屬性設置為false
2.對Item Layout的根控制項android:descendantFocusability="blocksDescendant"
例如:
<RelativeLayout
xmlns:android=""
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dip"
android:background="#ffffffff"
android:descendantFocusability="blocksDescendant >
<LinearLayout
<RatingBar
android:id="@+id/rb_bookRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="2.0"
style="@style/RatingBar"
android:isIndicator="true"
/>
</LinearLayout>
<Button
android:id="@+id/btn_schele"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:focusable="false"
android:text="影訊"
style="@style/Button"
/>
</RelativeLayout>

3. Android listview 點擊 是當前選中條變色 其他不變(也就是鎖定焦點)這個怎麼做

是點擊效果還是點後一直變?
點擊效果的話用selector,在item的layout中設置背景就ok了;
一直變的話 監聽listview的點擊事件。

4. android 中 listview 設置選中 獲取焦點 然後點擊一個button刪除此item 應該怎麼實現

對listView設置監聽 刪除本條數據 實現刪除item功能

5. 關於ListView如何使其獲得焦點

在布局文件中的layout里加入這句話即可android:descendantFocusability="blocksDescendants"

6. android ListView刷新焦點問題

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="">
<item android:state_window_focused="false"
android:drawable="@drawable/沒有焦點時的圖片背景" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable=
"@drawable/非觸摸模式下獲得焦點並單擊時的背景圖片" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/觸摸模式下單擊時的背景圖片" />
<item android:state_selected="true"
android:drawable="@drawable/選中時的圖片背景" />
<item android:state_focused="true"
android:drawable="@drawable/獲得焦點時的圖片背景" />
</selector>

試試

7. android listview item textview怎麼獲取焦點

當前textview.setFocusable(true);就可以了,你在載入listview item的adapter(適配器里)通過position給當前item設置焦點,就可以實現item獲取焦點

8. android listView,Button,android:descendantFocusability、android:focusable都已經添加無法獲取焦點

beforeDescendants:viewgroup會優先其子類控制項而獲取到焦點
afterDescendants:viewgroup只有當其子類控制項不需要獲取焦點時才獲取焦點
blocksDescendants:viewgroup會覆蓋子類控制項而直接獲得焦點

所以,你應該用第二個設置,這樣子控制項就可以優先獲取到焦點了

閱讀全文

與androidlistview設置焦點相關的資料

熱點內容
單片機串口發射怎麼回事 瀏覽:472
程序員假裝自己很忙 瀏覽:798
程序員能力關鍵詞 瀏覽:615
plc編程高級視頻教程 瀏覽:610
java遞歸求n 瀏覽:84
python絕對路徑導入 瀏覽:126
nex5g加密 瀏覽:975
18的空島伺服器地址 瀏覽:86
程序員要學什麼硬體 瀏覽:666
股票漲跌源碼怎麼看 瀏覽:576
加密軟體做法 瀏覽:57
美國程序員有多少中國人 瀏覽:741
人民日報app里怎麼看新聞早班車 瀏覽:587
忘了app怎麼辦 瀏覽:531
如何用雲伺服器做雲平台 瀏覽:301
非箍筋加密區剪力 瀏覽:119
利聯科技伺服器卡怎麼辦 瀏覽:386
js和python哪個好 瀏覽:463
c盤的哪些文件夾沒用 瀏覽:83
文件為什麼會超出在線解壓限制 瀏覽:591