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

熱點內容
心靈解壓大笑視頻 瀏覽:598
東學西學單片機 瀏覽:671
phpstudy做伺服器如何使用 瀏覽:950
平板怎麼下載安卓國服 瀏覽:775
源碼時代找不到工作會退錢嗎 瀏覽:214
如何app搭建伺服器 瀏覽:846
javastringblob 瀏覽:297
王瑤pdf 瀏覽:859
開掛軟體顯示請連接伺服器地址 瀏覽:917
蘋果怎麼下載安卓倩女 瀏覽:586
vip藍光視頻解析網站源碼 瀏覽:942
伺服器ps1ps2是什麼意思 瀏覽:858
seo命令 瀏覽:869
可代理雲伺服器 瀏覽:973
本地伺服器連接失敗是什麼意思 瀏覽:868
華為平板如何將應用app分身 瀏覽:899
微信顯示無法連接到伺服器1302什麼意思 瀏覽:627
java有哪些函數 瀏覽:754
隨遇app怎麼收費 瀏覽:203
如何將家用電腦做伺服器外網 瀏覽:805