ExpandableListView首次加載所有展開,而不能點擊收縮呢?java
一、首次加載所有展開:
ide
mDownloadListView.setAdapter(mDownloadAdapter); for (int i = 0; i < downloadGroup.size(); i++) { mDownloadListView.expandGroup(i); }
提醒:加載前別忘了判斷adapter是否爲空和有沒有Group數據哦、函數
二、不能點擊收縮:spa
mDownloadListView.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { // TODO Auto-generated method stub return true; } });
OK了,把他的組點擊事件屏蔽。呵呵、code
三、ExpandableListView的長按事件
網上的資料不少,可是真正管用的沒幾個,最後找到一個確實能夠用的,在這分享下:
(1)orm
//長按事件 mExpandableListView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub menu.setHeaderTitle("選擇操做"); menu.add(0, DOWNLOAD_RETRY, 0, "重試"); menu.add(0, DOWNLOAD_DEL, 0, "刪除"); menu.add(0, DOWNLOAD_START, 0, "啓動"); } });
(2)事件
/** * 長按菜單響應函數 */ @Override public boolean onContextItemSelected(MenuItem item) { // TODO Auto-generated method stub //關鍵代碼 ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo(); int type = ExpandableListView.getPackedPositionType(info.packedPosition); if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {//上面的type設定這裏類型的斷定!這裏是child斷定! int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); //在child斷定裏面,獲取該child所屬group! int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); //在child斷定裏面,獲取該child所屬position! switch (item.getItemId()) { case DOWNLOAD_RETRY: makeTextShort("我是重試"); break; case DOWNLOAD_DEL: makeTextShort("我是刪除"); break; case DOWNLOAD_START: makeTextShort("我是啓動"); default: break; } return true; } return false; }
四、目前上面浮動的未安裝View沒有實現,iOS的貌似是叫IphoneTreeView 。ci