在左Android開始有SDK提供ExpandListView的可扩展列表,而在iOS下有很多第三方做好的Demo,这里我是參照iOS下RATreeView这个第三方库实现的。

本文代码:须要在3.1以上版本号执行。

假设是用3.0版本号须要将Vec2换成Piont

原文地址:http://blog.csdn.net/qqmcy/article/details/29559241

代码下载:http://download.csdn.net/detail/qqmcy/7469387

以下说下用法:

DJDataObject.h   数据模型类

//
// DJDataObject.h
// testthirdone
//
// Created by 杜甲 on 14-6-7.
//
// #ifndef __testthirdone__DJDataObject__
#define __testthirdone__DJDataObject__ #include "cocos2d.h"
USING_NS_CC; class DJDataObject :public Ref
{ public: CREATE_FUNC(DJDataObject);
virtual bool init();
std::string name;
std::vector<DJDataObject*> children; void initWithNameAndChildren(std::string name,std::vector<DJDataObject*> data_vec); }; #endif /* defined(__testthirdone__DJDataObject__) */

DJDataObject.cpp

//
// DJDataObject.cpp
// testthirdone
//
// Created by 杜甲 on 14-6-7.
//
// #include "DJDataObject.h" bool DJDataObject::init()
{
bool bRet = false;
do { bRet = true;
} while (0); return bRet;
} void DJDataObject::initWithNameAndChildren(std::string name,std::vector<DJDataObject*> data_vec)
{
this->name = name;
this->children = data_vec; }

ListViewTest.h  可扩展列表的使用类,将这个布局addChild到场景中就OK。

//
// ListViewTest.h
// testthirdone
//
// Created by 杜甲 on 14-6-9.
//
// #ifndef __testthirdone__ListViewTest__
#define __testthirdone__ListViewTest__ #include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "DJDataObject.h" USING_NS_CC;
using namespace ui; class ListViewTest : public ui::Layout
{
public: CREATE_FUNC(ListViewTest);
virtual bool init(); std::vector<DJDataObject*> data_vec; }; #endif /* defined(__testthirdone__ListViewTest__) */

ListViewTest.cpp

//
// ListViewTest.cpp
// testthirdone
//
// Created by 杜甲 on 14-6-9.
//
// #include "ListViewTest.h"
#include "DJTreeNode.h"
#include "DJTreeNodeInfo.h"
#include "DJListView.h" bool ListViewTest::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!ui::Layout::init()); setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
setBackGroundColor(Color3B(18, 23, 222)); std::vector<DJDataObject*>temp1;
std::vector<DJDataObject*>temp2;
std::vector<DJDataObject*>temp3;
std::vector<DJDataObject*>temp4; DJDataObject* data7 = DJDataObject::create();
data7->retain();
//initWithNameAndChildren 參数1:当前数据内容。 參数2 :子集
data7->initWithNameAndChildren("数据1-1-1", temp4);
temp1.push_back(data7); DJDataObject* data3 = DJDataObject::create();
data3->retain();
data3->initWithNameAndChildren("数据1-1", temp1); DJDataObject* data4 = DJDataObject::create();
data4->retain();
data4->initWithNameAndChildren("数据1-2", temp4); for (int i = 0; i < 7; i++)
{
DJDataObject* data6 = DJDataObject::create();
data6->retain();
data6->initWithNameAndChildren("数据h", temp3);
temp2.push_back(data6);
} DJDataObject* data1 = DJDataObject::create();
data1->retain();
data1->initWithNameAndChildren("数据r", temp2); DJDataObject* data = DJDataObject::create();
data->retain();
std::vector<DJDataObject*>temp;
temp.push_back(data3);
temp.push_back(data4); data->initWithNameAndChildren("数据1", temp); data_vec.push_back(data);
data_vec.push_back(data1); auto winSize = Director::getInstance()->getWinSize(); auto listView1 = DJListView::create();
listView1->setSize(winSize);
listView1->addExpandedListView(data_vec);
addChild(listView1); bRet = true;
} while (0); return bRet;
}

这里帖出的是用法,稍后我提供实现的类的下载地址。

实现效果:

之后我会把以下的实现传上来,如今网络有限制不让传。

这里也贴出实现类

DJTreeNodeInfo.h 节点信息类

//
// DJTreeNodeInfo.h
// testthirdone
//
// Created by 杜甲 on 14-6-6.
//
// #ifndef __testthirdone__DJTreeNodeInfo__
#define __testthirdone__DJTreeNodeInfo__ #include "cocos2d.h"
USING_NS_CC;
class DJTreeNode; class DJTreeNodeInfo :public Ref
{ public:
CREATE_FUNC(DJTreeNodeInfo);
virtual bool init(); bool expanded; int treeDepthLevel;
int siblingsNumber;
int positionInsiblings; DJTreeNodeInfo* parent; DJTreeNode* parentTreeNode; std::vector<DJTreeNodeInfo*> children; void* item;
std::vector<DJTreeNode*> childrenTreeNodes; void initWithParent(DJTreeNode* parent1 , std::vector<DJTreeNode*> children1); DJTreeNodeInfo* getParent();
std::vector<DJTreeNodeInfo*> getChildren(); }; #endif /* defined(__testthirdone__DJTreeNodeInfo__) */

DJTreeNodeInfo.cpp

//
// DJTreeNodeInfo.cpp
// testthirdone
//
// Created by 杜甲 on 14-6-6.
//
// #include "DJTreeNodeInfo.h"
#include "DJTreeNode.h" bool DJTreeNodeInfo::init()
{
bool bRet = false;
do { bRet = true;
} while (0); return bRet;
} void DJTreeNodeInfo::initWithParent(DJTreeNode *parent1, std::vector<DJTreeNode *> children1)
{
this->parentTreeNode = parent1;
this->childrenTreeNodes = children1;
} DJTreeNodeInfo* DJTreeNodeInfo::getParent()
{
if (this->parent == nullptr)
{
this->parent = this->parentTreeNode->treeNodeInfo1(); }
return nullptr;
} std::vector<DJTreeNodeInfo*> DJTreeNodeInfo::getChildren()
{
if (this->children.size() == 0 )
{
std::vector<DJTreeNodeInfo*> treeNodesInfos;
for (int i = 0; i < this->childrenTreeNodes.size(); i++) {
DJTreeNode* treeNode = this->childrenTreeNodes.at(i);
treeNodesInfos.push_back(treeNode->treeNodeInfo1());
this->children = treeNodesInfos;
}
}
return this->children;
}

DJTreeNode.h  节点类

//
// DJTreeNode.h
// testthirdone
//
// Created by 杜甲 on 14-6-6.
//
// #ifndef __testthirdone__DJTreeNode__
#define __testthirdone__DJTreeNode__ #include "cocos2d.h"
USING_NS_CC; class DJTreeNodeInfo; class DJTreeNode :public Ref{ public:
CREATE_FUNC(DJTreeNode);
virtual bool init(); bool expanded;
bool visible;
DJTreeNode* parent;
std::vector<DJTreeNode*> children;
DJTreeNodeInfo* treeNodeInfo;
DJTreeNodeInfo* treeNodeInfo1(); void* item; int treeDepthLevel; void initWithItem(void* item , DJTreeNode* parent , bool expanded); void addChildNode(DJTreeNode* child); std::vector<DJTreeNode*> visibleDescendants();
int numberOfVisibleDescendants(); void collapse();
void expand(); int startIndex();
int endIndex(); bool isVisible(); int treeDepthLevel1(); }; #endif /* defined(__testthirdone__DJTreeNode__) */

DJTreeNode.cpp

//
// DJTreeNode.cpp
// testthirdone
//
// Created by 杜甲 on 14-6-6.
//
// #include "DJTreeNode.h"
#include "DJTreeNodeInfo.h" typedef enum DJTreeDepthLevel {
DJTreeDepthLevelNotInitialized
} DJTreeDepthLevel; bool DJTreeNode::init()
{
bool bRet = false;
do { bRet = true;
} while (0); return bRet;
} void DJTreeNode::initWithItem(void *item, DJTreeNode *parent, bool expanded)
{
this->treeDepthLevel = DJTreeDepthLevelNotInitialized;
this->item = item;
this->parent = parent;
this->expanded = expanded; } bool DJTreeNode::isVisible()
{
return this->parent->expanded || this->parent == nullptr;
} void DJTreeNode::addChildNode(DJTreeNode *child)
{
// if (this->children.size() > 0) {
// this->children.clear();
// }
std::vector<DJTreeNode*> children1(this->children); children1.push_back(child);
this->children = children1;
} int DJTreeNode::numberOfVisibleDescendants()
{
return (int)visibleDescendants().size();
} std::vector<DJTreeNode*> DJTreeNode::visibleDescendants()
{
std::vector<DJTreeNode*> visibleDescendants; try {
if (expanded)
{ if (this->children.size() > 0)
{
// log("children.size() = %lu",children.size());
for (int i = 0; i < this->children.size(); i++)
{
// log("i = %d",i);
DJTreeNode* treeNode = children.at(i); visibleDescendants.push_back(treeNode);
if (treeNode->expanded)
{
std::vector<DJTreeNode*> tree_vec = treeNode->visibleDescendants();
for (int i = 0; i < tree_vec.size(); i++)
{ visibleDescendants.push_back(tree_vec.at(i));
} } } } } } catch (std::out_of_range & exc) {
log("exc.what() = %s",exc.what()); } // log("visibleDescendants = %zd",visibleDescendants.size());
return visibleDescendants;
} void DJTreeNode::expand()
{
this->expanded = true;
if (this->parent != nullptr) {
this->parent->expand();
} } void DJTreeNode::collapse()
{
this->expanded = false;
for (int i = 0; i < children.size(); i++)
{
DJTreeNode* treeNode = children.at(i);
treeNode->collapse();
}
} int DJTreeNode::startIndex()
{
int startIndex;
if (this->parent->parent == nullptr) {
startIndex = 0;
}else{
startIndex = this->parent->startIndex() + 1;
} for (int i = 0 ; i < this->parent->children.size() ; i++)
{
DJTreeNode* treeNode = this->parent->children.at(i); if (treeNode != this) {
startIndex += 1;
if (treeNode->expanded) {
startIndex += treeNode->numberOfVisibleDescendants();
}
}
else
{
break;
} }
return startIndex;
} int DJTreeNode::endIndex()
{
int startIndex = this->startIndex();
return startIndex + numberOfVisibleDescendants(); } DJTreeNodeInfo* DJTreeNode::treeNodeInfo1()
{
if (this->treeNodeInfo == nullptr)
{
DJTreeNodeInfo* treeNodeInfo = DJTreeNodeInfo::create();
treeNodeInfo->initWithParent(this->parent, this->children);
treeNodeInfo->treeDepthLevel = treeDepthLevel1();
treeNodeInfo->siblingsNumber = (int)this->parent->children.size(); for (int i = 0; i < this->parent->children.size(); i++)
{ if (this->parent->children.at(i) == this)
{
treeNodeInfo->positionInsiblings = i;
}
}
this->treeNodeInfo = treeNodeInfo; }
this->treeNodeInfo->item = this->item;
this->treeNodeInfo->expanded = this->expanded;
return this->treeNodeInfo;
} int DJTreeNode::treeDepthLevel1()
{
if (this->treeDepthLevel == DJTreeDepthLevelNotInitialized)
{
int treeDepthLevel = 0;
DJTreeNode* current = this->parent->parent;
while (current != nullptr) {
treeDepthLevel++;
current = current->parent;
}
this->treeDepthLevel = treeDepthLevel; }
return this->treeDepthLevel;
}

DJTreeNodeCollectionController.h  节点控制类

//
// DJTreeNodeCollectionController.h
// testthirdone
//
// Created by 杜甲 on 14-6-6.
//
// #ifndef __testthirdone__DJTreeNodeCollectionController__
#define __testthirdone__DJTreeNodeCollectionController__ #include "cocos2d.h"
USING_NS_CC; class DJTreeNode;
class DJTreeNodeInfo; class DJTreeNodeCollectionController : public Ref
{ public: CREATE_FUNC(DJTreeNodeCollectionController);
virtual bool init(); DJTreeNode* root; void addTreeNode(DJTreeNode* treeNode); DJTreeNode* treeNodeForIndex(int index); DJTreeNode* treeNodeForIndex(int index , DJTreeNode* currentTreeNode); int indexForItem(void* item); int indexForItem(void* item , DJTreeNode* currentTreeNode); }; #endif /* defined(__testthirdone__DJTreeNodeCollectionController__) */

DJTreeNodeCollectionController.cpp

//
// DJTreeNodeCollectionController.cpp
// testthirdone
//
// Created by 杜甲 on 14-6-6.
//
// #include "DJTreeNodeCollectionController.h"
#include "DJTreeNode.h" bool DJTreeNodeCollectionController::init()
{
bool bRet = false;
do {
root = DJTreeNode::create();
root->retain();
root->initWithItem(nullptr, nullptr, true); bRet = true;
} while (0); return bRet; } void DJTreeNodeCollectionController::addTreeNode(DJTreeNode *treeNode)
{
if (treeNode->parent == nullptr)
{
this->root->addChildNode(treeNode); treeNode->parent = this->root;
}else
{
treeNode->parent->addChildNode(treeNode);
if (treeNode->expanded)
{
treeNode->expand();
}
}
} DJTreeNode* DJTreeNodeCollectionController::treeNodeForIndex(int index)
{
if (index < 0)
{
return nullptr;
} return treeNodeForIndex(index, this->root);
} DJTreeNode* DJTreeNodeCollectionController::treeNodeForIndex(int index, DJTreeNode *currentTreeNode)
{
for (int i = 0; i < currentTreeNode->children.size(); i++)
{
DJTreeNode* treeNode = currentTreeNode->children.at(i);
if (treeNode->startIndex() == index)
{
return treeNode;
}else if (index <= treeNode->endIndex())
{
return treeNodeForIndex(index, treeNode);
}
}
return nullptr;
} int DJTreeNodeCollectionController::indexForItem(void *item)
{
return indexForItem(item, this->root);
} int DJTreeNodeCollectionController::indexForItem(void *item, DJTreeNode *currentTreeNode)
{
std::vector<DJTreeNode*> array = this->root->visibleDescendants();
for (int i = 0; i < array.size(); i++)
{
DJTreeNode* treeNode = array.at(i);
if (treeNode->item == item)
{
return i;
}
} return -1;
}

DayReportListAdapter.h  

//
// DayReportListAdapter.h
//
//
// Created by 杜甲 on 14-6-4.
//
// #ifndef __ht_mobile_cpp__DayReportListAdapter__
#define __ht_mobile_cpp__DayReportListAdapter__ #include "cocos2d.h"
#include "../../cocos2d/cocos/ui/CocosGUI.h" USING_NS_CC; class DayReportListAdapter :public ui::Layout
{ public:
CREATE_FUNC(DayReportListAdapter);
virtual bool init();
ui::Text* organName; ui::Text* prem_day; ui::Text* prem_month;
};
#endif /* defined(__ht_mobile_cpp__DayReportListAdapter__) */

DayReportListAdapter.cpp

//
// DayReportListAdapter.cpp
//
//
// Created by 杜甲 on 14-6-4.
//
// #include "DayReportListAdapter.h"
bool DayReportListAdapter::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!ui::Layout::init());
setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);
float topLength = 30; organName = ui::Text::create();
organName->setFontSize(30);
organName->setColor(Color3B::BLACK);
addChild(organName); auto rp_organName = ui::RelativeLayoutParameter::create();
rp_organName->setMargin(ui::Margin(30,topLength,0,0));
rp_organName->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT);
organName->setLayoutParameter(rp_organName); prem_month = ui::Text::create();
prem_month->setFontSize(30);
prem_month->setColor(Color3B::BLACK);
addChild(prem_month); auto rp_prem_month = ui::RelativeLayoutParameter::create();
rp_prem_month->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT);
rp_prem_month->setRelativeName("rp_prem_month");
rp_prem_month->setMargin(ui::Margin(0,topLength,50,0)); prem_month->setLayoutParameter(rp_prem_month); prem_day = ui::Text::create();
prem_day->setFontSize(30); prem_day->setColor(Color3B::BLACK);
addChild(prem_day); auto rp_prem_day = ui::RelativeLayoutParameter::create();
rp_prem_day->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL);
// rp_prem_day->setRelativeToWidgetName("rp_prem_month");
rp_prem_day->setMargin(ui::Margin(30,topLength,0,0));
prem_day->setLayoutParameter(rp_prem_day); bRet = true;
} while (0);
return bRet; }

DJListView.h   

//
// DJListView.h
// testthirdone
//
// Created by 杜甲 on 14-6-8.
//
// #ifndef __testthirdone__DJListView__
#define __testthirdone__DJListView__ #include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "DJDataObject.h"
#include "DJExpandListView.h" USING_NS_CC;
using namespace ui; class DJListView :public ui::Layout
{ public:
CREATE_FUNC(DJListView); virtual bool init(); void selectedItemEvent(Ref *pSender, cocos2d::ui::ListView::EventType type); Size winSize; std::vector<DJDataObject*> data_vec;
void addExpandedListView( std::vector<DJDataObject*> data_vec); private: ui::ListView* listView; ssize_t numberOfCellsInListView(void *item); void* treeViewItem( int index, void *item); DJTreeNodeCollectionController* treeNodeCollectionController;
std::vector<void*> childrenForItem(void *item);
void setupTreeStructure();
void setupTreeStructureWithParentNode(DJTreeNode* parentTreeNode ,int treeDepthLevel); void collapseCellForTreeNode(cocos2d::Ref *pSender,DJTreeNode* treeNode);
DJTreeNode* treeNodeForIndex(int index);
void expandCellForTreeNode(cocos2d::Ref *pSender , DJTreeNode* treeNode); }; #endif /* defined(__testthirdone__DJListView__) */

DJListView.cpp

//
// DJListView.cpp
// testthirdone
//
// Created by 杜甲 on 14-6-8.
//
// #include "DJListView.h"
#include "DayReportListAdapter.h"
#include "DJTreeNode.h"
#include "DJTreeNodeInfo.h" #include "DJTreeNodeCollectionController.h" bool DJListView::init()
{
bool bRet = false; do {
CC_BREAK_IF(!ui::Layout::init()); setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);
winSize = Director::getInstance()->getWinSize(); bRet = true;
} while (0);
return bRet;
} void DJListView::addExpandedListView( std::vector<DJDataObject*> data_vec1)
{
data_vec = data_vec1; listView = ui::ListView::create(); listView->setDirection(cocos2d::ui::ScrollView::Direction::VERTICAL);
listView->setTouchEnabled(true);
listView->setBounceEnabled(true);
listView->setSize(Size(winSize.width,winSize.height - 100));
listView->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
listView->setBackGroundColor(Color3B::WHITE); listView->addEventListener(CC_CALLBACK_2(DJListView::selectedItemEvent, this)); auto rp_listView = ui::RelativeLayoutParameter::create();
rp_listView->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL);
listView->setLayoutParameter(rp_listView); setupTreeStructure(); // set model for (int i = 0; i < treeNodeCollectionController->root->numberOfVisibleDescendants(); i++)
{
DJDataObject* dobject = static_cast<DJDataObject*>(treeNodeForIndex(i)->item) ; auto tableLayout1 = DayReportListAdapter::create();
tableLayout1->setSize(Size(winSize.width, 1));
tableLayout1->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
tableLayout1->setBackGroundColor(Color3B(189, 203, 222));
listView->pushBackCustomItem(tableLayout1);
tableLayout1->organName->setString(dobject->name);
tableLayout1->prem_day->setString(StringUtils::format("%d",i));
tableLayout1->prem_month->setString("fffff");
} auto tableLayout2 = DayReportListAdapter::create();
tableLayout2->setSize(Size(winSize.width, 1));
tableLayout2->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
tableLayout2->setBackGroundColor(Color3B(189, 203, 222));
listView->pushBackCustomItem(tableLayout2); auto layout21 = ui::Layout::create();
layout21->setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);
layout21->setSize(winSize);
layout21->addChild(listView);
layout21->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
layout21->setBackGroundColor(Color3B(89, 203, 222)); auto tableLayout1 = ui::Layout::create();
tableLayout1->setSize(winSize);
tableLayout1->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
tableLayout1->setBackGroundColor(Color3B(189, 203, 222));
//listView->pushBackCustomItem(tableLayout1); listView->setGravity(cocos2d::ui::ListView::Gravity::CENTER_VERTICAL);
listView->setItemsMargin(100.0f); auto page = ui::PageView::create();
page->setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);
page->setSize(winSize);
page->addPage(layout21); page->addPage(tableLayout1);
addChild(page); auto rp_page = ui::RelativeLayoutParameter::create();
rp_page->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL);
page->setLayoutParameter(rp_page); } void DJListView::selectedItemEvent(cocos2d::Ref *pSender, cocos2d::ui::ListView::EventType type)
{ switch (type) {
case ui::ListView::EventType::ON_SELECTED_ITEM_END:
{
ui::ListView* listView = static_cast<ui::ListView*>(pSender); DJTreeNode* treeNode = treeNodeForIndex((int)listView->getCurSelectedIndex()); if (treeNode->children.size() == 0)
{
return; } if (treeNode->expanded) {
collapseCellForTreeNode(pSender, treeNode);
}else{
log("treeNode->expanded = %d",treeNode->expanded);
expandCellForTreeNode(pSender, treeNode);
} listView->refreshView();
}
break; default:
break;
} } ssize_t DJListView::numberOfCellsInListView(void *item)
{
if (item == nullptr) {
log("%zd",data_vec.size()); return data_vec.size();
} DJDataObject* data = static_cast<DJDataObject*>(item);
return data->children.size(); } void* DJListView::treeViewItem( int index, void *item)
{
DJDataObject* data = static_cast<DJDataObject*>(item);
if (item == nullptr) {
return data_vec.at( index );
}
return data->children.at( index ); } std::vector<void*> DJListView::childrenForItem(void *item)
{
std::vector<void*> children ;
ssize_t numberOfChildren = numberOfCellsInListView(item); for (int i = 0; i< numberOfChildren ; i++)
{
children.push_back(treeViewItem(i, item)); } return children;
} DJTreeNode* DJListView::treeNodeForIndex(int index)
{
return treeNodeCollectionController->treeNodeForIndex(index);
} void DJListView::setupTreeStructure()
{
treeNodeCollectionController = DJTreeNodeCollectionController::create();
treeNodeCollectionController->retain();
setupTreeStructureWithParentNode(nullptr, 0);
} void DJListView::setupTreeStructureWithParentNode(DJTreeNode* parentTreeNode ,int treeDepthLevel)
{
std::vector<void*> children; if (parentTreeNode == nullptr)
{
children = childrenForItem(nullptr);
}else
{
children = childrenForItem(parentTreeNode->item);
}
log("setupTreeStructureWithParentNode 循环前"); try {
for (int i = 0; i < children.size(); i++)
{
log(" i = %d",i); void* item = children.at(i);
DJTreeNode* treeNode = DJTreeNode::create();
treeNode->retain();
treeNode->initWithItem(item, parentTreeNode, false);
setupTreeStructureWithParentNode(treeNode, treeDepthLevel + 1);
treeNodeCollectionController->addTreeNode(treeNode);
}
} catch (std::out_of_range & exc)
{
log("exc.what() = %s",exc.what());
} } void DJListView::collapseCellForTreeNode(cocos2d::Ref *pSender,DJTreeNode* treeNode)
{
log("treeNode->startIndex() = %d , treeNode->endIndex() = %d",treeNode->startIndex(),treeNode->endIndex()); for (int index = treeNode->startIndex() + 1; index <= treeNode->endIndex(); index++)
{
ui::ListView* listView1 = static_cast<ui::ListView*>(pSender);
listView1->removeItem(treeNode->startIndex() + 1); }
treeNode->collapse(); } void DJListView::expandCellForTreeNode(cocos2d::Ref *pSender , DJTreeNode* treeNode)
{
log("treeNode->startIndex() = %d , treeNode->endIndex() = %d",treeNode->startIndex(),treeNode->endIndex());
treeNode->expand();
// ui::ListView* listView1 = static_cast<ui::ListView*>(pSender);
// listView1->insertDefaultItem(0);
for (int index = treeNode->startIndex() + 1; index <= treeNode->endIndex();index++ )
{ DJDataObject* dobject = static_cast<DJDataObject*>(treeNodeForIndex(index)->item) ; auto tableLayout1 = DayReportListAdapter::create();
tableLayout1->setSize(Size(winSize.width, 1));
tableLayout1->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
tableLayout1->setBackGroundColor(Color3B(189, 203, 222));
listView->insertCustomItem(tableLayout1, index);
//pushBackCustomItem(tableLayout1);
tableLayout1->organName->setString(dobject->name);
tableLayout1->prem_day->setString(StringUtils::format("%d",index));
tableLayout1->prem_month->setString("fffff"); } }

cocos2d-x3.1 下实现相似Android下ExpandListView的效果的更多相关文章

  1. Android下Cocos2d创建HelloWorld工程

    最近在搭建Cocos2d的环境,结果各种问题,两人弄了一天才能搞好一个环境-! -_-!! 避免大家也可能会遇到我这种情况,所以写一个随笔,让大家也了解下如何搭建吧- 1.环境安装准备 下载 tadp ...

  2. 【FAQ】Ubuntu环境下ant编译android代码问题

    在Ubuntu14.04环境下,编译android程序时候,运行ant debug的时候出现如下异常:

  3. Android下/data/data/<package_name>/files读写权限

    今天将更新模块拿到android上面测试的时候,发现在创建writablepath.."upd/"目录的时候出现Permission Denied提示BTW:我使用的是lfs来创建 ...

  4. Linux学习心得之 Linux下命令行Android开发环境的搭建

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Linux学习心得之 Linux下命令行Android开发环境的搭建 1. 前言2. Jav ...

  5. Android下读取logcat的信息

    有时我们需要在程序执行进程中遇到一些异常,需要收集一logcat的信息,android下就可以使用以下方法获取: private static String getLogcatInfo(){ Stri ...

  6. Android下OpenCV的环境搭建

    目录(?)[-] 前言 系统环境 相关工具 Android ADT环境搭建 Android SDK环境变量的配置 Android NDK的安装与配置 OpenCV for Android 环境搭建 基 ...

  7. Android下添加新的自定义键值和按键处理流程

            Android下添加新的自定义键值和按键处理流程     说出来不怕大家笑话,我写这篇博客的原因在于前几天去一个小公司面试Android系统工程师,然后在面试的时候对方的技术总监问了我 ...

  8. Android下的数据储存方式(三)

      Android下最好的数据储存方式:关系型数据库sqlite.   数据库的创建:使用SqliteOpenHelper类 结合SqliteOpenHelper类和SQLiteDatabase类的帮 ...

  9. [转]Android下拉刷新完全解析,教你如何一分钟实现下拉刷新功能

    版权声明:本文出自郭霖的博客,转载必须注明出处. 转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9255575 最近项目中需要用到L ...

随机推荐

  1. Linux中断分层--工作队列

    1. 工作队列是一种将任务推后执行的方式,它把推后的任务交由一个内核线程去执行.这样中断的下半部会在进程上下文执行,他允许重新调度甚至睡眠.每个被推后的任务叫做“工作”,由这些工作组成的队列称为工作队 ...

  2. PIE SDK同态滤波

    1.算法功能简介 同态滤波是减少低频增加高频,从而减少光照变化并锐化边缘或细节的图像滤波方法. 同态滤波的流程为:空间域图像→对数运算→傅里叶正变换→同态滤波――傅里叶逆变换→指数运算→同态滤波结果. ...

  3. Git~分支真的很轻

    轻,让人觉得很爽 所有源代码管理工具都有管理分支的功能,git当然也不例外,而且git的分支是非常轻的,不像tfs,svn那样,复制一大堆代码,git只记录变化的内容,有本地分支与远程分支之分,原则上 ...

  4. Understanding Java 8 Streams API---reference

    http://java.amitph.com/2014/01/understanding-java-8-streams-api.html Since past few versions, Java h ...

  5. multiprocessing 模块

    multiprocessing模块 进程对象 创建 p = Process(target=foo, args=(param,)) 属性 p.daemon: True为守护进程, 守护进程内无法再开启子 ...

  6. 浏览器后退->清除原页面div中填写的数据

    需求说明:页面表单用前端用div布局,提交之后跳转到另一个页面,但是考虑到客户奇怪的脑回路,可能会点击浏览器的后退按钮,不知道是个体情况还是都是一样,原本div中填写的数据还依然存在,所以需要让页面在 ...

  7. [转] .net core Session , Working with a distributed cache

    本文转自:https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed By Steve Smith+ Di ...

  8. 打包.NET Core的程序到一个单独的可执行文件

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:打包.NET Core的程序到一个单独的可执行文件.

  9. vue分页

    1.依赖文件 <link href="/css/index.css" rel="stylesheet" type="text/css" ...

  10. Redis简介及持久化

    Redis是一个key-value数据库,他不仅性能强劲,而且还具有复制特性以及为解决问题而生的独一无二的数据模型.可用于缓存.消息队列.发布.订阅消息.商品列表和评论列表等场景.Redis提供了5种 ...