![Android 開發(fā) listview QQ多級(jí)列表的實(shí)現(xiàn)_第1頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/31/9fdcc43f-fb6b-4d0c-9784-60cf08fb4db9/9fdcc43f-fb6b-4d0c-9784-60cf08fb4db91.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、android 開發(fā) listview qq多級(jí)列表的實(shí)現(xiàn)代碼 主類package com.android.qu.antking.list; import android.app.activity;import android.content.context;import android.os.bundle;import android.view.layoutinflater;import android.view.view;import android.view.viewgroup;import android.widget.baseexpandablelistadapter;import
2、android.widget.expandablelistview;import android.widget.imageview;import android.widget.textview; import java.util.*; public class mymain extends activity /author antkingwei private list> parentlist=new arraylist>(); private list>> childlist = new arraylist>>(); expendadapter adapt
3、er; expandablelistview exlist; private string listname = new string"我的好友","高中學(xué)生","高校學(xué)生","移動(dòng)開發(fā)","網(wǎng)站建設(shè)","一般伴侶"private string childtitle= new string"丫寧","王八銳","小鳥","連超","董二丫"private string chil
4、dmood= new string"我喜愛王銳","我就是王八","我也喜愛王銳","上邊一群傻帽","同樓上"private int headimage=new intr.drawable.ning,r.drawable.rui,r.drawable.niao,r.drawable.lianchao,r.drawable.xiaoxiao; public void oncreate(bundle savedinstancestate) super.oncreate(savedinstances
5、tate); setcontentview(r.layout.main); exlist = (expandablelistview) this.findviewbyid(r.id.expandablelistview1); parentlist =getparentlist(); childlist = getchildlist(); adapter = new expendadapter(mymain.this, parentlist, childlist); exlist.setadapter(adapter); exlist.setgroupindicator(null); exlis
6、t.setdivider(null); public list> getparentlist() list> list = new arraylist>(); for(int i=0;i map curgroupmap = new hashmap(); list.add(curgroupmap); curgroupmap.put("list", listnamei); return list; public list>> getchildlist() list>> list1 = new arraylist>>(); f
7、or (int i = 0; i list> children = new arraylist>(); for (int j = 0; j map curchildmap = new hashmap(); children.add(curchildmap); curchildmap.put("title", childtitlej); curchildmap.put("mood", childmoodj); curchildmap.put("head", headimagej); list1.add(children);
8、return list1; 復(fù)制代碼代碼 自定義的adapterpackage com.android.qu.antking.list; import android.content.context;import android.view.layoutinflater;import android.view.view;import android.view.viewgroup;import android.widget.baseexpandablelistadapter;import android.widget.imageview;import android.widget.textview
9、;import android.widget.toast; import java.util.*; public class expendadapter extends baseexpandablelistadapter private layoutinflater layoutinflater; private context mcontext; private list> parentlist = new arraylist>(); private list>> childlist = new arraylist>>(); public expendad
10、apter(context mcontext,list> parentlist,list>> childlist) this.mcontext = mcontext; this.parentlist = parentlist; this.childlist = childlist; layoutinflater = layoutinflater.from(mcontext);public object getchild(int groupposition, int childposition) / todo auto-generated method stubreturn c
11、hildlist.get(groupposition).get(childposition).get("title").tostring(); overridepublic long getchildid(int groupposition, int childposition) return childposition; overridepublic view getchildview(int groupposition, int childposition,boolean islastchild, view convertview, viewgroup parent)
12、if(convertview =null)convertview = layoutinflater.inflate(r.layout.childlist, null); final imageview head=(imageview)convertview.findviewbyid(r.id.headimage); head.setimageresource(integer.valueof(childlist.get(groupposition).get(childposition).get("head").tostring(); final textview title=
13、(textview)convertview.findviewbyid(r.id.title); title.settext(childlist.get(groupposition).get(childposition).get("title").tostring(); final textview mood =(textview)convertview.findviewbyid(r.id.mood); mood.settext(childlist.get(groupposition).get(childposition).get("mood").tost
14、ring(); return convertview; overridepublic int getchildrencount(int groupposition) / todo auto-generated method stubreturn childlist.get(groupposition).size(); overridepublic object getgroup(int groupposition) / todo auto-generated method stubreturn parentlist.get(groupposition).get("list"
15、).tostring(); overridepublic int getgroupcount() / todo auto-generated method stubreturn parentlist.size(); overridepublic long getgroupid(int groupposition) / todo auto-generated method stubreturn groupposition; overridepublic view getgroupview(int groupposition, boolean isexpanded,view convertview
16、, viewgroup parent) if(convertview=null)convertview=layoutinflater.inflate(r.layout.parentlist, null); final textview list = (textview) convertview.findviewbyid(r.id.list); list.settext(parentlist.get(groupposition).get("list").tostring(); return convertview; overridepublic boolean hasstab
17、leids() / todo auto-generated method stubtoast.maketext(mcontext,"nihao",toast.length_short).show();return true; overridepublic boolean ischildselectable(int groupposition, int childposition) toast.maketext(mcontext, "這是第"+groupposition+"組,第"+childposition+"個(gè)"
18、, toast.length_short).show();return true; 復(fù)制代碼代碼 主布局文件 android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="drawable/back1" > 復(fù)制代碼代碼 parentlist布局 xmlns:android=" android:layout_width=
19、"fill_parent" android:orientation="horizontal" android:id="+id/parentlist" android:layout_height="wrap_content"> android:layout_width="60px" android:layout_height="60px" android:src="drawable/user_group" /> android:id="
20、+id/list" android:textsize="20px" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 復(fù)制代碼代碼 childlist布局 xmlns:android=" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="+id/childlist" android:orientation="horizontal" > android:paddingleft="20px" android:id="+id/headimage" android:src
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 房屋租賃合同的擔(dān)保合同
- 商砼購銷的合同
- 采購合同的主要類型
- 物流公司承運(yùn)合同
- 網(wǎng)絡(luò)營(yíng)銷執(zhí)行作業(yè)指導(dǎo)書
- 平面設(shè)計(jì)軟件應(yīng)用作業(yè)指導(dǎo)書
- 公司給員工的勞動(dòng)合同
- 2025年南京貨運(yùn)從業(yè)資格證500道題目答案大全
- 電力分配合同(2篇)
- 2024-2025學(xué)年高中英語課時(shí)分層作業(yè)3含解析新人教版選修9
- T-CACM 1560.6-2023 中醫(yī)養(yǎng)生保健服務(wù)(非醫(yī)療)技術(shù)操作規(guī)范穴位貼敷
- 人教版小學(xué)數(shù)學(xué)一年級(jí)下冊(cè)第1-4單元教材分析
- JTS-215-2018碼頭結(jié)構(gòu)施工規(guī)范
- 財(cái)務(wù)實(shí)習(xí)生合同
- 2024年長(zhǎng)沙衛(wèi)生職業(yè)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫含答案
- 地質(zhì)災(zāi)害危險(xiǎn)性評(píng)估的基本知識(shí)
- (正式版)SHT 3075-2024 石油化工鋼制壓力容器材料選用規(guī)范
- 出租房房東消防培訓(xùn)
- 2024年度-小學(xué)語文教師經(jīng)驗(yàn)交流
- 麻醉科質(zhì)量與安全管理小組工作計(jì)劃
- 認(rèn)識(shí)比例尺人教版課件
評(píng)論
0/150
提交評(píng)論