
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、android 開發(fā) listview qq多級列表的實現(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é)生","移動開發(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+"個"
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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 從“幫倒忙”開始
- 中國滌綸常溫濾料市場深度分析及行業(yè)前景展望報告
- 2025年移動通訊零部件項目可行性研究報告
- 2025年羅紋鋼圓鋼項目投資可行性研究分析報告
- 固體廢物治理改造項目可行性論證報告
- 2020-2025年中國廈門市投資環(huán)境行業(yè)市場運營現(xiàn)狀及投資方向研究報告
- 2020-2025年中國肌松藥行業(yè)發(fā)展?jié)摿Ψ治黾巴顿Y戰(zhàn)略咨詢報告
- 2025年派駐異地辦事處行業(yè)深度研究分析報告
- 擔(dān)保公司投資合同范本
- 2025年丙型肝炎抗原檢測試劑盒項目合作計劃書
- 2025春季學(xué)期少先隊工作安排表
- 學(xué)校2025年春季學(xué)期學(xué)校安全工作計劃+行事歷
- 2024中國糖果、巧克力制造市場前景及投資研究報告
- 第11課《山地回憶》說課稿 2024-2025學(xué)年統(tǒng)編版語文七年級下冊
- 2023年H3CNE題庫附答案
- 2024年首都醫(yī)科大學(xué)附屬北京安定醫(yī)院招聘筆試真題
- 【招商手冊】杭州ICON CENTER 社交娛樂中心年輕人潮流消費創(chuàng)新實驗
- 2024年同等學(xué)力申碩英語考試真題
- 2024年蘇州市職業(yè)大學(xué)單招職業(yè)適應(yīng)性測試題庫附答案
- GB 14907-2018鋼結(jié)構(gòu)防火涂料
- 10T每天生活污水處理設(shè)計方案
評論
0/150
提交評論