在平板上經(jīng)常能看到這種的情況:左邊是一個列表,右邊是列表項對應的內(nèi)容,當點擊某一個列表時,右邊內(nèi)容區(qū)也會隨之改變。下面使用Fragment簡單的demo:
思路:在MainActivity定義一個回調(diào)接口,并在列表點擊回調(diào)該接口,然后在內(nèi)容區(qū)的Fragment設置回調(diào),同時改變Fragment的顯示內(nèi)容。具體代碼如下:
主布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:divider="?android:attr/dividerVertical" android:showDividers="middle"> <ListView android:id="@+id/book_list" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <FrameLayout android:id="@+id/book_detail_container" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3"/> </LinearLayout>
分享題目:AndroidFragment實現(xiàn)列表和內(nèi)容聯(lián)動-創(chuàng)新互聯(lián)
分享鏈接:http://aaarwkj.com/article44/jcdee.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、標簽優(yōu)化、網(wǎng)站營銷、網(wǎng)站設計、網(wǎng)站策劃、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)