cocos2d-x3.1 下实现相似Android下ExpandListView的效果
在左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的效果的更多相关文章
- Android下Cocos2d创建HelloWorld工程
最近在搭建Cocos2d的环境,结果各种问题,两人弄了一天才能搞好一个环境-! -_-!! 避免大家也可能会遇到我这种情况,所以写一个随笔,让大家也了解下如何搭建吧- 1.环境安装准备 下载 tadp ...
- 【FAQ】Ubuntu环境下ant编译android代码问题
在Ubuntu14.04环境下,编译android程序时候,运行ant debug的时候出现如下异常:
- Android下/data/data/<package_name>/files读写权限
今天将更新模块拿到android上面测试的时候,发现在创建writablepath.."upd/"目录的时候出现Permission Denied提示BTW:我使用的是lfs来创建 ...
- Linux学习心得之 Linux下命令行Android开发环境的搭建
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Linux学习心得之 Linux下命令行Android开发环境的搭建 1. 前言2. Jav ...
- Android下读取logcat的信息
有时我们需要在程序执行进程中遇到一些异常,需要收集一logcat的信息,android下就可以使用以下方法获取: private static String getLogcatInfo(){ Stri ...
- Android下OpenCV的环境搭建
目录(?)[-] 前言 系统环境 相关工具 Android ADT环境搭建 Android SDK环境变量的配置 Android NDK的安装与配置 OpenCV for Android 环境搭建 基 ...
- Android下添加新的自定义键值和按键处理流程
Android下添加新的自定义键值和按键处理流程 说出来不怕大家笑话,我写这篇博客的原因在于前几天去一个小公司面试Android系统工程师,然后在面试的时候对方的技术总监问了我 ...
- Android下的数据储存方式(三)
Android下最好的数据储存方式:关系型数据库sqlite. 数据库的创建:使用SqliteOpenHelper类 结合SqliteOpenHelper类和SQLiteDatabase类的帮 ...
- [转]Android下拉刷新完全解析,教你如何一分钟实现下拉刷新功能
版权声明:本文出自郭霖的博客,转载必须注明出处. 转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9255575 最近项目中需要用到L ...
随机推荐
- oracle 基础知识(一)
Oracle 用户.权限.角色管理 01.概念 用户:对数据库的访问需要以适当的身份通过验证,这就是用户的作用:每个Oracle用户都有自己的用户名和密码,并且拥有他们所创建的任意表.视图和其他资源, ...
- shell 脚本学习之内部变量
一,$BASH Bash的二进制程序文件的路径 二,$BASH_ENV 这个环境变量会指向一个Bash的启动文件, 当一个脚本被调用的时候, 这个启动文件将会被读取. 三,$BASH_SUBSHELL ...
- React.js 小书 Lesson14 - 实战分析:评论功能(一)
作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson14 转载请注明出处,保留原文链接和作者信息. 课程到这里大家已经掌握了 React.js 的 ...
- nyoj 364——田忌赛马——————【贪心】
田忌赛马 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Here is a famous story in Chinese history. "That ...
- 结合manage.py,在flask项目中使用websocket模块--- flask-socketio
前言: - 为什么我要使用 flask-socketio模块,而不是flask-sockets? - 因为flask-socketio与前端流行的websocket库socke ...
- ajax实现的点击数目加1代码实例
ajax实现的点击数目加1代码实例:在点击按钮实现数字增加效果代码实例一章节中,介绍如何点击按钮实现数字加1的效果,但是好像并没有什么实际用处,下面就分享一段相对完整的能够在实际应用中派上用场的代码, ...
- 深入理解JavaScript系列(18):面向对象编程之ECMAScript实现(推荐)
介绍 本章是关于ECMAScript面向对象实现的第2篇,第1篇我们讨论的是概论和CEMAScript的比较,如果你还没有读第1篇,在进行本章之前,我强烈建议你先读一下第1篇,因为本篇实在太长了(35 ...
- ExcelHelper office 导出
要是服务器上没有装着excel 可以用c#导出excel表吗 2009-08-10 17:36 风之成 | 分类:办公软件 | 浏览2279次 租用的空间 服务器上没有装着office excel,可 ...
- 迟到的UED(转发)
2013UCAN用户体验设计论坛–精彩视频赏析 - 交互设计 博文 视觉设计 | TaoBaoUEDhttp://ued.taobao.org/blog/2013/09/2013ucan/
- Android4.4 在Framework新增内部资源编译不过的问题
如果在Frameworks新增内部资源,并在Java代码中使用类似形式来引用资源:com.android.internal.R.layout.xxx,需要在frameworks/base/core/r ...