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

熱點內容
資料庫查詢系統源碼 瀏覽:612
php5314 瀏覽:352
完美國際安裝到哪個文件夾 瀏覽:664
什麼app可以掃一掃做題 瀏覽:535
程序員編碼論壇 瀏覽:920
淘點是什麼app 瀏覽:656
中國高等植物pdf 瀏覽:450
51單片機時間 瀏覽:178
後台如何獲取伺服器ip 瀏覽:261
單片機流水燈程序c語言 瀏覽:230
程序員第二職業掙錢 瀏覽:235
運行里怎麼輸入伺服器路徑 瀏覽:835
pythonstepwise 瀏覽:505
劉一男詞彙速記指南pdf 瀏覽:58
php認證級別 瀏覽:364
方舟編譯啥時候推送 瀏覽:1006
php手機驗證碼生成 瀏覽:670
哲學思維pdf 瀏覽:12
凌達壓縮機有限公司招聘 瀏覽:529
weblogic命令部署 瀏覽:33