導航:首頁 > 操作系統 > 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設置焦點相關的資料

熱點內容
計算機編譯運行 瀏覽:636
單片機嵌套 瀏覽:986
python字元串中符號 瀏覽:787
python正則表達式貪婪模式 瀏覽:648
愛國精神指的是什麼app 瀏覽:408
壽司解壓系列全集視頻 瀏覽:913
物體三維重建演算法 瀏覽:984
fuli直播app哪個好 瀏覽:918
租辦公室用什麼app 瀏覽:106
醫師定期考核刷題app哪個好 瀏覽:338
導出dmp文件命令 瀏覽:288
手機百度網盤怎麼解壓密碼文件 瀏覽:585
索引重新編譯 瀏覽:606
命令與征服4免cd補丁完美版 瀏覽:428
kotlin編譯為native 瀏覽:142
家用編譯機 瀏覽:552
電子加密貨幣最新政策 瀏覽:383
androidcanvas撤銷 瀏覽:272
安卓手機怎麼把圖標全部下移 瀏覽:188
飢荒被伺服器踢出怎麼進 瀏覽:173