在左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. pg存储过程和sql语句块

    展E宝项目使用的是postgresql数据库,批量发送红包需求,需要采用存储过程来初始化红包记录数据. 创建存储过程语句有固定的架子,如下 CREATE OR REPLACE FUNCTION pub ...

  2. PHP jQuery实现上传图片时预览图片的功能实例

    在PHP项目开发中,有时候经常需要做添加图片的功能.添加图片时,一般需要即时预览上传的图片.下面这个例子就是简单的预览上传图片功能,代码如下(分两部分): 1.HTML代码: <div clas ...

  3. Flask 编写http接口api及接口自动化测试

    片言 此文中代码都是笔者工作中源码,所以不会很完整,主要摘常见场景的api片段用以举例说明 另:此文主要针对自动化测试人员,尤其有python基础阅读更佳. 笔者使用 python3.6 + post ...

  4. Linux Tomcat 80端口 Port 80 required by Tomcat v8.5 Server at localhost is already in use.

    Port 80 required by Tomcat v8.5 Server at localhost is already in use. The server may already be run ...

  5. [转]v$parameter, v$parameter2, v$system_parameter, v$system_parameter2, v$spparameter区别

    本文转自:http://blog.csdn.net/huang_xw/article/details/617389 1 v$parameter v$parameter显示的是session级的参数. ...

  6. sql 创建用户脚本

    USE master go  CREATE LOGIN jiazhuang --用户名 WITH PASSWORD = 'sa', --密码 DEFAULT_DATABASE = JiaZhuan, ...

  7. 【转载】BootStrap表格组件bootstrap table详解

    (转载,来源“脚本之家”,作者不详) 一.Bootstrap Table的引入 关于Bootstrap Table的引入,一般来说还是两种方法: 1.直接下载源码,添加到项目里面来.由于Bootstr ...

  8. python学习(三)--跟着例子写的贴吧网页爬取

    from urllib import requestimport urllib #爬贴吧网页文件到本地.首先在本地打开百度贴吧 搜索 java吧#第一页的内容是:http://tieba.baidu. ...

  9. java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ 解决方案

    //第一个异常 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysq ...

  10. C# 矩阵运算和一些基本的几何运算

    以前工作中写的,这里备个份,有可能用到 基本的矩阵运算类,测试20阶以内应该没啥问题,超过20阶不好使... /// <summary> /// 矩阵 异常 512索引 1024无解 20 ...