




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
可以指定layout_weightlayout_weigthlayout_weightlayout_widthheight=”0dp”配合使用,指定的控件所占寬/高ExpandableListViewListViewListView;ListView類(lèi)似;AdapterpublicViewgetGroupView()viewview :返回某個(gè)位置對(duì)應(yīng)的孩子的view對(duì)象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查詢(xún)可能是耗時(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,"歷史緩存對(duì)象可復(fù)用:"+position);view=holderViewHolder //取出ViewHolder象}elseLog.i(TAGView1.復(fù)用歷史緩存view對(duì)象減少布局文件轉(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對(duì)象容器,保存
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對(duì)象容器,用來(lái)保存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è)可見(jiàn)的條目如果最后一個(gè)可見(jiàn)條目就是數(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è)存放用戶(hù)安裝的一個(gè)存放系統(tǒng)自帶的ListViewgetCount方法,返回的條目的個(gè)數(shù)為用戶(hù)的+系統(tǒng)自L(fǎng)istView的滾動(dòng),動(dòng)態(tài)設(shè)置分類(lèi)標(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對(duì)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)部類(lèi),保存View中的孩子的引入staticclassViewHolderImageView //圖標(biāo)TextView //名稱(chēng)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è)問(wèn)Chebox2個(gè)問(wèn)題;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);}} //通過(guò)數(shù)據(jù)beanPopupWindowPopupPopupWindow須定義成ActivityPopupPopupWindowPopupWindows對(duì)象一定要記得設(shè)置背景,否則不能獲得焦點(diǎn),與實(shí)現(xiàn)動(dòng)畫(huà);privateprivatePopupWindow1.創(chuàng)建popupTextViewtvnewTextView(getApplicationContext()); //創(chuàng)建Popup對(duì)象(高100,寬pupop=newPopupWindow(tv,LayoutParams.WRAPCONTENT,LayoutParams.WRAPCONTENT);//設(shè)置背景(一定要設(shè)置,否則不能獲得焦點(diǎn),不 //設(shè)置顯示位置,與布局(左上角對(duì)其,距離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)畫(huà)集合,widgets是一個(gè)嵌入其他應(yīng)用中執(zhí)行的小程序(如嵌入在桌面,有點(diǎn)類(lèi)似于快捷圖標(biāo)widgets的選項(xiàng)框,4.0widgets注意:如果在模擬器上widget出不來(lái),可能是文件中配置了程序的安裝路徑,去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;通過(guò)上面對(duì)生命周期的分析,可將啟動(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ā)廣播開(kāi)啟activity開(kāi)PendingIntentIntentintent=newIntent(); PendingIntentpendingIntentPendingIntent.getBroadcast(getApplicationContext(),0,intent,0);}timer.schedule(task2000 //循環(huán)執(zhí)行}publicvoidonDestroy(){task=null;timer=null;}publicclasspublicclassProcessWidgetextendsAppWidgetProvider{publicvoidonEnabled(Contextcontext)//
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 充分準(zhǔn)備的行政組織理論試題及答案
- 西藥批發(fā)企業(yè)客戶(hù)關(guān)系管理策略與實(shí)施考核試卷
- 嵌入式開(kāi)發(fā)考試案例解析試題及答案
- 行政組織理論的實(shí)踐性分析與2025年試題及答案
- 四級(jí)軟件測(cè)試職業(yè)生涯規(guī)劃試題及答案
- 軟件測(cè)試工程師考試常見(jiàn)問(wèn)題試題及答案
- 嵌入式系統(tǒng)的故障排除指南試題及答案
- 疾病預(yù)防控制檢測(cè)考核試卷
- 油品質(zhì)量分析與檢測(cè)技術(shù)考核試卷
- 開(kāi)發(fā)中的最佳實(shí)踐試題及答案
- 民用爆炸物品倉(cāng)庫(kù)管理規(guī)定培訓(xùn)課件
- 10篇說(shuō)明文閱讀題及答案
- 項(xiàng)目式學(xué)習(xí)的探索
- (完整版)【鋼琴譜】大魚(yú)鋼琴譜
- 藥品從輕處罰申請(qǐng)書(shū)范本
- 工藝品軟裝施工方案
- 二手車(chē)鑒定及評(píng)估教案
- 【培養(yǎng)】(完整版)師帶徒培養(yǎng)方案
- 一文讀懂-特魯索綜合征病例、影像、診斷、治療
- 體育旅游課件第二章體育旅游資源
- 2023年科技特長(zhǎng)生招生考試試卷
評(píng)論
0/150
提交評(píng)論