cocos2d-x-2.0 ListView使用
由于cocos2d-x没有给出例子,所以代码有点长。我都写了注释,应该很容易理解。
ListViewTestLayer.h头文件
[cpp]
//
// ListViewTestLayer.h
// 2dxDemo
//
// Created by Yanghui Liu on 12-6-26.
// Copyright (c) 2012年 BoyoJoy. All rights reserved.
//
#ifndef _dxDemo_ListViewTestLayer_h
#define _dxDemo_ListViewTestLayer_h
#include "cocos2d.h"
#include "CCListView.h"
#include <list.h>
#include <string.h>
USING_NS_CC;
using namespace cocos2d::extension;
class ListViewTestLayer : public CCLayer , public CCListViewDelegate {
public:
ListViewTestLayer();
~ListViewTestLayer();
virtual bool init();
LAYER_NODE_FUNC(ListViewTestLayer);
virtual void visit();
public:
// 继承自CCListViewDelegate所需要实现的方法
virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data);
virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data);
virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data);
virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data);
private:
//显示list的状态的一个lable
CCLabelTTF *m_InfoLabel;
private:
// 存放的List数据
std::list<std::string> *m_pDataList;
CCListView *m_pListView;
//是否刷新,即reload
bool m_bFresh;
void initData();
};
#endif
cpp的实现:
[cpp]
//
// ListViewTestLayer.cpp
// 2dxDemo
//
// Created by Yanghui Liu on 12-6-26.
// Copyright (c) 2012年 BoyoJoy. All rights reserved.
//
#include "ListViewTestLayer.h"
#include "CCListViewCell.h"
ListViewTestLayer::ListViewTestLayer(){
}
ListViewTestLayer::~ListViewTestLayer(){
}
void ListViewTestLayer::initData(){
m_bFresh = true;
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
m_pDataList = new std::list<std::string>;
for (int i=0; i<15; i++) {
char info[20];
sprintf(info, "My Cell %d", i);
m_pDataList->push_back(info);
}
// 初始化控件ListView
CCListView *listView = CCListView::viewWithMode(CCListViewModeVertical);
listView->setContentSize(
相关新闻>>
- 发表评论
-
- 最新评论 更多>>