您好,登錄后才能下訂單哦!
效果圖如下所示:
1、在Adapter中加入如下代碼
<pre ><span >private int </span><span >clickTemp </span>= -<span >1</span><span >;</span><span >//</span><span ><em>TODO </em></span><span ><em>被選擇的</em></span><span ><em>item</em></span><span ><em>下標</em></span></pre><p></p> <pre ><span ><em>/** </em></span><span ><em> * </em></span><span ><em>TODO </em></span><span ><em>傳入下標,設置被選擇的</em></span><span ><em>item </em></span><span ><em> </em></span><span ><em>* </em></span><span ><em> * </em></span><span ><strong><em>@param </em></strong></span><span ><em>position </em></span><span ><em> </em></span><span ><em>*/ </em></span><span >public void </span><span >setSelection</span>(<span >int </span>position) { <span >clickTemp </span>= position<span >; </span>}</pre> <br> <pre></pre>
2、在Adapter的getView方法中加入如下代碼
<p></p> <p></p><pre name="code" class="java"><pre ><span >//</span><span ><em>TODO </em></span><span ><em>點擊改變</em></span><span ><em>item</em></span><span ><em>底部控件狀態 </em></span><span >if </span>(<span >clickTemp </span>== position) {<span >//</span><span ><em>TODO </em></span><span ><em>選中的</em></span><span ><em>item</em></span><span ><em>顯示底部控件 </em></span><span ><em> </em></span>typeHolder.<span >item_gv_viewBottom</span>.setVisibility(View.<span ><em>VISIBLE</em></span>)<span >; </span>} <span >else </span>{<span >//</span><span ><em>TODO </em></span><span ><em>未選中的</em></span><span ><em>item</em></span><span ><em>隱藏底部控件 </em></span><span ><em> </em></span>typeHolder.<span >item_gv_viewBottom</span>.setVisibility(View.<span ><em>INVISIBLE</em></span>)<span >; </span>}</pre><p></p> <pre></pre>
3、修改OnItemClickListener代碼<br>
<pre name="code" class="java"><pre ><span ><em>/** </em></span><span ><em> * item</em></span><span ><em>點擊事件 </em></span><span ><em> </em></span><span ><em>*/ </em></span>AdapterView.OnItemClickListener <span >mItemClickListener </span>= <span >new </span>AdapterView.OnItemClickListener() { <span >@Override </span><span > </span><span >public void </span><span >onItemClick</span>(AdapterView<?> parent<span >, </span>View view<span >, int </span>position<span >, long </span>id) { <span >myGridViewAdapter</span>.setSelection(position)<span >;</span><span >//</span><span ><em>TODO </em></span><span ><em>傳入當前點擊</em></span><span ><em>item</em></span><span ><em>的下標 </em></span><span ><em> </em></span><span >myGridViewAdapter</span>.notifyDataSetChanged()<span >;</span><span >//</span><span ><em>TODO </em></span><span ><em>刷新</em></span><span ><em>Adapter </em></span><span ><em> </em></span>} }<span >;</span></pre> <pre></pre> <br> <br> <p></p> <p><br> <br> </p> </pre></pre>
以上所述是小編給大家介紹的Android實現騰訊新聞的新聞類別導航效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。