android中listView单选

设置ListView为单选模式
<ol class="linenums"><li value="1" class="L0"><span class="pln">        </span><span class="tag"><ListView</span></li><li class="L1"><span class="pln">            </span><span class="atn">android:id</span><span class="pun">=</span><span class="atv">"@+id/lv_category"</span></li><li class="L2"><span class="pln">            </span><span class="atn">android:choiceMode</span><span class="pun">=</span><span class="atv">"singleChoice"</span></li><li class="L3"><span class="pln">            </span><span class="atn">android:layout_width</span><span class="pun">=</span><span class="atv">"0dp"</span></li><li class="L4"><span class="pln">            </span><span class="atn">android:layout_height</span><span class="pun">=</span><span class="atv">"match_parent"</span></li><li class="L5"><span class="pln">            </span><span class="atn">android:layout_weight</span><span class="pun">=</span><span class="atv">"2"</span></li><li class="L6"><span class="pln">            </span><span class="atn">android:divider</span><span class="pun">=</span><span class="atv">"@drawable/iv_left_item_separate_line"</span><span class="pln"> </span><span class="tag">></span></li><li class="L7"><span class="pln">        </span><span class="tag"></ListView></span></li></ol>

设置Item的Layout的背景为一个Selector:
bg_listview_item.xml

<ol class="linenums"><li value="1" class="L0"><span class="tag"><selector</span><span class="pln"> </span><span class="atn">xmlns:android</span><span class="pun">=</span><span class="atv">"http://schemas.android.com/apk/res/android"</span><span class="tag">></span></li><li class="L1"><span class="pln">    </span><span class="tag"><item</span><span class="pln"> </span><span class="atn">android:state_activated</span><span class="pun">=</span><span class="atv">"true"</span><span class="pln"> </span><span class="atn">android:drawable</span><span class="pun">=</span><span class="atv">"@android:drawable/list_selector_background_selected"</span><span class="pln"> </span><span class="tag">/></span></li><li class="L2"><span class="pln">    </span><span class="tag"><item</span><span class="pln"> </span><span class="atn">android:drawable</span><span class="pun">=</span><span class="atv">"@color/transparent"</span><span class="pln"> </span><span class="tag">/></span></li><li class="L3"><span class="tag"></selector></span></li></ol>
<ol class="linenums"><li value="1" class="L0"><span class="pun"><?</span><span class="pln">xml version</span><span class="pun">=</span><span class="str">"1.0"</span><span class="pln"> encoding</span><span class="pun">=</span><span class="str">"utf-8"</span><span class="pun">?></span></li><li class="L1"><span class="tag"><TextView</span><span class="pln"> </span><span class="atn">xmlns:android</span><span class="pun">=</span><span class="atv">"http://schemas.android.com/apk/res/android"</span></li><li class="L2"><span class="pln">    </span><span class="atn">android:layout_width</span><span class="pun">=</span><span class="atv">"match_parent"</span></li><li class="L3"><span class="pln">    </span><span class="atn">android:layout_height</span><span class="pun">=</span><span class="atv">"match_parent"</span></li><li class="L4"><span class="pln">    </span><span class="atn">android:background</span><span class="pun">=</span><span class="atv">"@drawable/bg_listview_item"</span></li><li class="L5"><span class="pln">    </span><span class="atn">android:gravity</span><span class="pun">=</span><span class="atv">"center"</span></li><li class="L6"><span class="pln">    </span><span class="atn">android:minHeight</span><span class="pun">=</span><span class="atv">"80dp"</span></li><li class="L7"><span class="pln">    </span><span class="atn">android:textColor</span><span class="pun">=</span><span class="atv">"@color/black"</span></li><li class="L8"><span class="pln">    </span><span class="atn">android:textSize</span><span class="pun">=</span><span class="atv">"26sp"</span><span class="pln"> </span><span class="tag">/></span></li></ol>
转载:http://www.pocketdigi.com/20120714/890.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值