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

熱點內容
命令提示符垃圾清理 瀏覽:801
javachar1 瀏覽:999
lcd單片機投影儀用久了會發黃 瀏覽:749
王者榮耀游戲內進攻主宰命令 瀏覽:213
周立功單片機發展有限公司 瀏覽:612
iphone未成年怎麼付款app 瀏覽:988
蘋果app是英文怎麼改 瀏覽:837
51單片機485通信 瀏覽:270
符咒全書pdf 瀏覽:565
海底撈app簽到怎麼弄不成了 瀏覽:862
安卓php伺服器搭建 瀏覽:259
京東直營網掙用什麼APP 瀏覽:825
傑克豆車機怎麼安裝app 瀏覽:32
app查余額怎麼有兩個金額 瀏覽:305
小程序仿今日頭條源碼 瀏覽:277
框架源碼研讀 瀏覽:447
仙侶奇緣3如何架設伺服器 瀏覽:954
單片機RRC指令 瀏覽:889
默認加密文件密碼 瀏覽:5
怎麼用反詐中心app查詢電話 瀏覽:710