版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
可以指定layout_weightlayout_weigthlayout_weightlayout_widthheight=”0dp”配合使用,指定的控件所占寬/高ExpandableListViewListViewListView;ListView類似;AdapterpublicViewgetGroupView()viewview :返回某個(gè)位置對應(yīng)的孩子的view對象view布局 //父publicclassExpandParentInfo{//父publicclassExpandParentInfo{privateStringname;privateintid;privateList<ExpandChildrenInfo>}//子publicclassExpandChildrenInfoprivateintprivateStringprivateString}//子 publicList<ExpandParentInfo>queryExpandData()List<ExpandParentInfo>List<ExpandParentInfo>list=newArrayList<ExpandParentInfo>(10);Databasedb=getDB();Cursorc=db.rawQuery("SELECTidx,nameFROMclasslist",null);while(c.moveToNext()){ExpandParentInfoparentnewExpandParentInfo(c.getInt(0c.getString(1));getChildren(parent,db); //獲取還在}close(c,return}@paramprivatevoidgetChildren(ExpandParentInfoparent, Databasedb){List<ExpandChildrenInfo>list=newArrayList<ExpandChildrenInfo>(10);Stringsql="SELECT_id,number,nameFROMtable"+parent.getId();Cursorc=db.rawQuery(sql,null);while(c.moveToNext())ExpandChildrenInfoinfo=newExpandChildrenInfo(c.getInt(0),c.getString(2),}this.close(c,null);}List<ExpandParentInfo>List<ExpandParentInfo>datas=dao.queryExpandData();ExpandableListViewelv=(ExpandableListView) elv.setAdapter(newBaseExpandableListAdapter(){publicViewgetGroupView(intgroupPosition,booleani panded,ViewconvertView,ViewGroupparent){TextViewtv=newTextView(getApplicationContext()); "+datas.get(groupPosition).getName());return}publicViewgetChildView(intgroupPosition,intchildPosition,isLastChild,ViewconvertView,ViewGroupparent)TextViewtv=newTextView(getApplicationContext());ExpandChildrenInfoinfo=return"+info.getName()+"+}@param publicintgetChildrenCount(intgroupPosition)return}publicintgetGroupCount()return}publicbooleanisChildSelectable(intgroupPosition,intchildPosition)return}publicbooleanhasStableIds()return}publiclonggetGroupId(intgroupPosition)return}publicObjectgetGroup(intgroupPosition)return}publiclonggetChildId(intgroupPosition,intchildPosition)return}publicObjectgetChild(intgroupPosition,intchildPosition)return}ListViewfastScrollEnabledprivateBaseAdapter*privateBaseAdapter*privateHandlerhandler=newHandler()//數(shù)據(jù)適配器publicvoidhandleMessage(android.os.Messagemsg){ //加載進(jìn)度條if(adapter==null){ lv_call_sms_safe=(ListView)adapteradapter=newMyCallSmsSafeAdapter();}else //復(fù)用舊的數(shù)據(jù)適配器,通知數(shù)據(jù)}privatevoidfillData(){ //顯示加載//dao查詢可能是耗時(shí)的操作,在新 newThread()publicvoidrun()if(numbers!=null){numbers.addAll(dao.queryPartBlackNumbers(startIndex,maxNumber));}elsenumbers=dao.queryPartBlackNumbers(startIndex,} }privateclassMyCallSmsSafeAdapterextendsBaseAdapterpublicintgetCount()1.listView展示的條數(shù)return}publicViewgetView(finalintposition,ViewconvertView,ViewGroupparent)2.具體顯示的條目Viewview=ViewHolderholder Viewif(convertViewnull&&convertViewinstanceofRelativeLayoutLog.i(TAG,"歷史緩存對象可復(fù)用:"+position);view=holderViewHolder //取出ViewHolder象}elseLog.i(TAGView1.復(fù)用歷史緩存view對象減少布局文件轉(zhuǎn)化成view2.查找孩子也是個(gè)耗時(shí)的操作,在創(chuàng)建view把孩子 給存起TextViewtv_number=(TextView)view.findViewById(R.id.tv_number);TextViewtv_mode=(TextView)view.findViewById(R.id.tv_mode);ImageViewiv_remove=(ImageView)view.findViewById(R.id.iv_remove);holder=newViewHolder(); View對象容器,保存
holder.tv_mode=tv_mode;holder.tv_number=tv_number;holder.iv_remove=iv_remove; //將holder}BlackNumberblackNum=numbers.get(position);BlackNumberblackNum=numbers.get(position);holder.iv_remove.setOnClickListener(newOnClickListener(){publicvoidonClick(Viewv)BlackNumbertempNum=numbers.get(position);除}if(blackNum.getMode().equals(BlackNumberDao.MODE )){ }return}publicObjectgetItem(intposition)return}publiclonggetItemId(intposition)4.獲取選中條目的return}publicbooleanisEnabled(intposition)//return}}ViewListViewView中的孩子,定義成static/**/**View對象容器,用來保存ListView條目的View中的孩 staticclassViewHolder{TextViewtv_number;TextViewtv_mode;ImageViewiv_remove;}ListView3 privatevoidinitListViewScrollListener(){lv_call_sms_safe.setOnScrollListener(newOnScrollListener(){//當(dāng)滾動(dòng)狀體發(fā)生變化的時(shí)候調(diào)用的方法(滾動(dòng)狀態(tài):1.手指按下移動(dòng);2.慣性滾動(dòng)即publicvoidonScrollStateChanged(AbsListViewview,intscrollState)switch(scrollState)case //在靜止?fàn)顟B(tài)下關(guān)心最后一個(gè)可見的條目如果最后一個(gè)可見條目就是數(shù)據(jù)適配器里面的最后一個(gè),加載 intposition=intsize=if(position==size-1)if(startIndextotalCount }startIndex+= }casecase態(tài)}}//當(dāng)listviewpublicvoidonScroll(AbsListViewview,intfirstVisibleItem,intinttotalItemCount)}}將中所有安裝的應(yīng)用分割成2個(gè)集合一個(gè)存放用戶安裝的一個(gè)存放系統(tǒng)自帶的ListViewgetCount方法,返回的條目的個(gè)數(shù)為用戶的+系統(tǒng)自ListView的滾動(dòng),動(dòng)態(tài)設(shè)置分類標(biāo)題;具**填充數(shù)據(jù)privatevoidfillData()newThread()publicvoidrun()appInfos=userAppInfos=newsystemAppInfos=new//系統(tǒng)的for(AppInfoappInfo:appInfos)if(appInfo.isUserApp())}//更新界面操作,Activity中的方法,它是運(yùn)行在主 的,原理是利用runOnUiThread(newRunnable()publicvoidrun()if(adapter==null)adapter=newAppManagerAdapter();}else}}ListViewprivateclassAppManagerAdapterextendsBaseAdapter{publicintgetCount()returnuserAppInfos.size()+systemAppInfos.size()+}publicViewgetView(intposition,ViewconvertView,ViewGroupparent)1.提示標(biāo)題條目==if(position0 //返回TextViewTextViewtv=newTextView(getApplicationContext());tv.setTextuserAppInfos.sizereturn}if(position==userAppInfos.size()+1){ //返回TextView對TextViewtv=newTextView(getApplicationContext());tv.setTextsystemAppInfos.sizereturn}//==2.程序標(biāo)題條目==Viewview=null;ViewHolderholdernull;if(convertView!=null&&convertViewinstanceofRelativeLayout){view=convertView;holder=(ViewHolder)}elseholder=newViewHolder();holder.iv_Icon=(ImageView)view.findViewById(R.id.iv_app_icon);holder.tv_name=(TextView)view.findViewById(R.id.tv_app_name);}AppInfoappInfo=if(position<=userAppInfos.size())appInfo=userAppInfos.get(position-}elseappInfo=systemAppInfos.get(position-userAppInfos.size()- }holder.tv_location.setText(appInfo.isInRom()?" 內(nèi)存":"外部 returnreturn}}/**靜態(tài)內(nèi)部類,保存View中的孩子的引入staticclassViewHolderImageView //圖標(biāo)TextView //名稱TextView } ListView的滾 *添加滾動(dòng)privatevoidsetOnScrollListener(){lv_app_manager.setOnScrollListener(newOnScrollListener(){//滾動(dòng)狀態(tài)發(fā)生變化.publicvoidonScrollStateChanged(AbsListViewview,intscrollState)firstVisibleItempublicvoidonScroll(AbsListViewview,intfirstVisibleItem,intinttotalItemCount)//界面初始化的時(shí)候,也會(huì)執(zhí)行滾 //根據(jù)當(dāng)前滾動(dòng)的狀態(tài),更新tv_statusif(userAppInfos!=null&&systemAppInfos!=null)if(firstVisibleItem>=userAppInfos.size()+1){tv_status.setTextsystemAppInfos.size}else}}}}CheckboxlistView的第一個(gè)條目的checkbox選中時(shí),拖動(dòng),至第一個(gè)條目移除屏幕,這時(shí)checkbox也選中了;有條目中含有checkbox控件時(shí),條目的onitemclick失效;ListViewgetViewview1個(gè)問Chebox2個(gè)問題;beanbeancheckboxclickfocus,android:clickable="false"條目的OnItemClickListener,手動(dòng)設(shè)置界面checkbox與數(shù)據(jù)bean的選中狀getViewbeancheckbox的選中狀態(tài);lv_process_manager.setOnItemClickListener(newOnItemClickListener(){publicvoidlv_process_manager.setOnItemClickListener(newOnItemClickListener(){publicvoidonItemClick(AdapterView<?>parent,Viewview,intposition,long{TaskInfotaskInfo=(TaskInfo)if(taskInfo!=null){ //取反//執(zhí)行上面那句代碼實(shí)際,數(shù)據(jù)bean已選擇,但是界面上的checkboxCheckBoxcb=(CheckBox)view.findViewById(R.id.cb_status);}} //通過數(shù)據(jù)beanPopupWindowPopupPopupWindow須定義成ActivityPopupPopupWindowPopupWindows對象一定要記得設(shè)置背景,否則不能獲得焦點(diǎn),與實(shí)現(xiàn)動(dòng)畫;privateprivatePopupWindow1.創(chuàng)建popupTextViewtvnewTextView(getApplicationContext()); //創(chuàng)建Popup對象(高100,寬pupop=newPopupWindow(tv,LayoutParams.WRAPCONTENT,LayoutParams.WRAPCONTENT);//設(shè)置背景(一定要設(shè)置,否則不能獲得焦點(diǎn),不 //設(shè)置顯示位置,與布局(左上角對其,距離left的距離50,距離top為100)pupop.showAtLocation(tvavailsdGravity.LEFT|Gravity.TOP50protectedvoidonDestroy(){if(pupop!=null&&pupop=null;}}popup1popup存在,即刪除掉if1popup存在,即刪除掉if(popup!=null&&popup.isShowing()){popup=}2.指定要顯示的intlocationnew //獲取點(diǎn)擊的view置3.創(chuàng)建popuppopup.showAtLocation(parent,Gravity.LEFT|Gravity.TOP,70,location[1]);//ScaleAnimationsa=newScaleAnimation(0.5f,1.2f,0.5f,1.2f);TranslateAnimationta=newTranslateAnimation(0,20,0,0);AnimationSetset=new//縮放//位移效果//動(dòng)畫集合,widgets是一個(gè)嵌入其他應(yīng)用中執(zhí)行的小程序(如嵌入在桌面,有點(diǎn)類似于快捷圖標(biāo)widgets的選項(xiàng)框,4.0widgets注意:如果在模擬器上widget出不來,可能是文件中配置了程序的安裝路徑,去WidgetsAppWidetroviderpublic //元數(shù)據(jù)android:resource="@xml/example_appwidget_infoinitialLayout:minHeight/minWidth:widgetCategory:home_screen|keyguard:桌面|<appwidget-providerxmlns:android="http:// onReceive onEnabled widget創(chuàng)建時(shí)與當(dāng)時(shí)間片到的時(shí)候(updatePeriodMillis的設(shè)置的時(shí)間,默認(rèn)為半個(gè)小時(shí)( onDisabled() widget移除時(shí),執(zhí)行,表示禁用,可在此做一些掃尾的widgetwidget程間的通信,需要使用到ipcinterprocesscommunication;通過上面對生命周期的分析,可將啟動(dòng)服務(wù)放入onEnabledonDisabled中;java的序列化接口,widget就從這個(gè)公共的內(nèi)存中取數(shù)據(jù),publicclasspublicclassUpdateWidgetServiceextendsService/**定時(shí)任務(wù)privateTimerTasktask;privateTimertimer;publicvoidonCreate(){timer=newTimer();task=newTimerTask()publicvoidrun()//更新widgetAppWidgetManagerawm= ComponentNameprovidernew2個(gè)進(jìn)程間通信ipcinterprocesscommunicationRemoteViews實(shí)現(xiàn)了Parcelable接口RemoteViewsviews=new//設(shè)置數(shù)據(jù)MemoryInfomemoryInfo=Formatter.formatFileSize(getApplicationContext(),memoryInfo.availMem));Intent意圖,發(fā)廣播開啟activity開PendingIntentIntentintent=newIntent(); PendingIntentpendingIntentPendingIntent.getBroadcast(getApplicationContext(),0,intent,0);}timer.schedule(task2000 //循環(huán)執(zhí)行}publicvoidonDestroy(){task=null;timer=null;}publicclasspublicclassProcessWidgetextendsAppWidgetProvider{publicvoidonEnabled(Contextcontext)//
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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ǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 辦公園林綠化合同范本
- 2025年度辦事處設(shè)計(jì)及智能化辦公系統(tǒng)合同
- 兒童玩具商標(biāo)轉(zhuǎn)讓居間合同
- 玻璃制品廠出租居間合同
- 第三人房產(chǎn)抵押擔(dān)保合同
- 網(wǎng)絡(luò)故障排除與維護(hù)手冊
- 工程中介居間合同
- 三農(nóng)產(chǎn)品安全檢測技術(shù)指南
- 大數(shù)據(jù)應(yīng)用與服務(wù)平臺(tái)建設(shè)項(xiàng)目合同
- 供應(yīng)商管理與采購合同談判規(guī)定
- 四川省自貢市2024-2025學(xué)年上學(xué)期八年級英語期末試題(含答案無聽力音頻及原文)
- 2025-2030年中國汽車防滑鏈行業(yè)競爭格局展望及投資策略分析報(bào)告新版
- 2025年上海用人單位勞動(dòng)合同(4篇)
- 二年級上冊口算題3000道-打印版讓孩子口算無憂
- 新疆烏魯木齊地區(qū)2025年高三年級第一次質(zhì)量監(jiān)測生物學(xué)試卷(含答案)
- 衛(wèi)生服務(wù)個(gè)人基本信息表
- 高中英語北師大版必修第一冊全冊單詞表(按單元編排)
- 新教科版科學(xué)小學(xué)四年級下冊全冊教案
- 苗圃建設(shè)項(xiàng)目施工組織設(shè)計(jì)范本
- 2024中考語文試卷及答案長沙
- 廣東省湛江市廉江市2023-2024學(xué)年八年級上學(xué)期期末考試數(shù)學(xué)試卷(含答案)
評論
0/150
提交評論